Page 1 of 1

Extracting regression results

Posted: Fri Aug 16, 2019 3:00 pm
by tjsduq64
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, p-value, 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

Re: Extracting regression results

Posted: Fri Aug 16, 2019 3:47 pm
by ChrisCharlton
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:

Code: Select all

# coefficients
coef(result_x36_main)

# standard errors
sqrt(diag(vcov(result_x36_main)))

# z-score
coef(result_x36_main)/sqrt(diag(vcov(result_x36_main)))

# p-values
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

Posted: Fri Aug 16, 2019 4:10 pm
by tjsduq64
ChrisCharlton wrote: Fri Aug 16, 2019 3:47 pm 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:

Code: Select all

# coefficients
coef(result_x36_main)

# standard errors
sqrt(diag(vcov(result_x36_main)))

# z-score
coef(result_x36_main)/sqrt(diag(vcov(result_x36_main)))

# p-values
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)))
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.

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

Re: Extracting regression results

Posted: Fri Aug 16, 2019 4:33 pm
by ChrisCharlton
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

Posted: Mon Aug 19, 2019 11:08 pm
by tjsduq64
ChrisCharlton wrote: Fri Aug 16, 2019 4:33 pm 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.
Thank you! texreg worked for me.