Hello,
what are some package options for extracting regression coefficients for R2MLwiN? I find that some packages won't work because they don't extract from S4 class. This is a type of models that I am running (i.e., two level random intercept model). I want to extract fixed and random effects coefficients and their standard errors, pvalue, etc.
sample < x36_i
model < bmi ~ 1 + female + age3 + age4 + lowincome + black + hispanics + (1  strata) + (1  id)
option < list(weighting = list(weightvar = c(NA, "w_mec"), standardised=TRUE))
result_x36_main < runMLwiN(Formula = model,
estoptions = option,
data = sample)
summary(result_x36_main)
Thank you,
Sun
Extracting regression results

 Posts: 1182
 Joined: Mon Oct 19, 2009 10:34 am
Re: Extracting regression results
Which packages are you trying? We might be able to investigate whether it is possible to add support in a later version of R2MLwiN.
You should be able to calculate these values yourself as follows:
You should be able to calculate these values yourself as follows:
Code: Select all
# coefficients
coef(result_x36_main)
# standard errors
sqrt(diag(vcov(result_x36_main)))
# zscore
coef(result_x36_main)/sqrt(diag(vcov(result_x36_main)))
# pvalues
2 * pnorm(abs(coef(result_x36_main)/sqrt(diag(vcov(result_x36_main)))), lower.tail = FALSE)
# 95% C.I. (lower)
coef(result_x36_main)  qnorm(.975) * sqrt(diag(vcov(result_x36_main)))
# 95% C.I. (upper)
coef(result_x36_main) + qnorm(.975) * sqrt(diag(vcov(result_x36_main)))
Re: Extracting regression results
Thank you so much for providing these codes! A package will be nice since I have multiple models to run, but I will have to use these for now unless others have better ideas.ChrisCharlton wrote: ↑Fri Aug 16, 2019 3:47 pmWhich packages are you trying? We might be able to investigate whether it is possible to add support in a later version of R2MLwiN.
You should be able to calculate these values yourself as follows:
Code: Select all
# coefficients coef(result_x36_main) # standard errors sqrt(diag(vcov(result_x36_main))) # zscore coef(result_x36_main)/sqrt(diag(vcov(result_x36_main))) # pvalues 2 * pnorm(abs(coef(result_x36_main)/sqrt(diag(vcov(result_x36_main)))), lower.tail = FALSE) # 95% C.I. (lower) coef(result_x36_main)  qnorm(.975) * sqrt(diag(vcov(result_x36_main))) # 95% C.I. (upper) coef(result_x36_main) + qnorm(.975) * sqrt(diag(vcov(result_x36_main)))
I am pretty new to R as well so I tried several packages  stargazer, texreg, and sjPlot.
stargazer gives "Error: $ operator not defined for this S4 class"
texreg doesn't specifically support R2MLwiN object, although it provides a table with fixed effect coefficients.
tab_model function in sjPlot gives "Could not access model information.Error: $ operator is invalid for atomic vectors"
Thank you.
Edit: I just realized that texreg does work and provides fixed and random effects coefficients. I will try to use this and confirm if this is sufficient.
Sun

 Posts: 1182
 Joined: Mon Oct 19, 2009 10:34 am
Re: Extracting regression results
Thanks for the references. We did work on getting texreg to work with R2MLwiN, see https://www.bristol.ac.uk/cmm/media/r2m ... ide04.Rout for another example of using this, as well as the memisc package. Last time I looked at stargazer it didn't provide the option to extend it for more estimation commands, but I will have another look to see whether this has changed. I am not familiar with sjPlot, so I will take a look at whether there are options for linking with this.
Re: Extracting regression results
Thank you! texreg worked for me.ChrisCharlton wrote: ↑Fri Aug 16, 2019 4:33 pmThanks for the references. We did work on getting texreg to work with R2MLwiN, see https://www.bristol.ac.uk/cmm/media/r2m ... ide04.Rout for another example of using this, as well as the memisc package. Last time I looked at stargazer it didn't provide the option to extend it for more estimation commands, but I will have another look to see whether this has changed. I am not familiar with sjPlot, so I will take a look at whether there are options for linking with this.