简体   繁体   中英

Calculating the standard error from p-value and beta in R

I have the output of two models - the first model was run using glm and the second model was run using lmekin. The input of both models was identical, except the lmekin model fitted a kinship matrix.

I want to take the coefficients from glm model and calculate the SE for those values using the p-values from the model run with lmekin.

Is this possible? I know you can manually calculate the SE using the square root of the diagonal elements of the unscaled covariance matrix. Would the following code therefore be successful in what I want to achieve?

beta <- glm_model$coefficients
nvar <- length(beta)
nfrail <- nrow(lmekin_model$var) - nvar
se <- sqrt(diag(lmekin_model$var)[nfrail + 1:nvar])

This seems iffy to me. Using estimated (and back computed) SE's from one model in another model that uses a different method and additional information does not seem likely to work.

However, many things that have seemed iffy to some at first have gone on to be proved correct and useful.

I would suggest simulating some data that is appropriate for your models, but being simulated you know what the "Truth" is. Then do your analyses and try your code to see what it shows. Then repeat the whole process a few times to see the variability between analyses. If your method does not work on the simulated data then you know that it cannot be trusted for the real data. But if it does work on the simulated data then it gives you more confidence in it being realistic for the real data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM