Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding weights statement #38

Open
joannegregory opened this issue Aug 5, 2021 · 1 comment
Open

Adding weights statement #38

joannegregory opened this issue Aug 5, 2021 · 1 comment

Comments

@joannegregory
Copy link

Hi Gianluca,

Thanks for the great package!

I was wondering if there was a way to add weights to fit.models.

Thanks,
Jo

@giabaio
Copy link
Owner

giabaio commented Aug 7, 2021

Jo,
The devel version of survHE (which you can download and install from this GitHub repo https://github.com/giabaio/survHE/tree/devel) does allow the use of the "weights" and "subset" options, which are already available in flexsurv.
For example, using that version of survHE and the default example dataset loaded up when you load the package, you can do

    library(survHE)
    m=fit.models(Surv(time,censored)~as.factor(arm), data=data, distr="wei", weights=data$sex+1, subset=data$ethnic==1)

    m

    Model fit for the Weibull AF model, obtained using Flexsurvreg
    (Maximum Likelihood Estimate). Running time: 0.036 seconds

                        mean       se      L95%      U95%
    shape           1.906546 0.215962 1.5269624  2.380490
    scale           9.293372 1.041126 7.4612937 11.575307
    as.factor(arm)1 0.402658 0.156897 0.0951459  0.710171

    Model fitting summaries
    Akaike Information Criterion (AIC)....: 321.547
    Bayesian Information Criterion (BIC)..: 328.161 

which produces the analysis using the variable sex (originally coded as 0/1 --- that's why I add 1 in the call to fit.models). Note that unless you attach the data, you need to refer to the variables using the "$" notation (so data$sex).

We haven't implemented the weighted versions under a Bayesian analysis (though I think this should be already fairly straightforward and possibly doable without fiddling with survHE under the INLA method). We can include that as part of the development targets, but it's not a top priority right now (unless we have more requests/urgency).

Note also that, in theory, you can create the weighted version of the variables "externally" and then pass the weighted dataset to the "normal" call to survHE --- that should also work...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants