简体   繁体   English

从 R 中的 p 值和 beta 计算标准误差

[英]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.我有两个模型的输出 - 第一个模型使用 glm 运行,第二个模型使用 lmekin 运行。 The input of both models was identical, except the lmekin model fitted a kinship matrix.两个模型的输入是相同的,只是 lmekin 模型拟合了亲属关系矩阵。

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.我想从 glm 模型中获取系数,并使用 lmekin 运行的模型中的 p 值计算这些值的 SE。

Is this possible?这可能吗? I know you can manually calculate the SE using the square root of the diagonal elements of the unscaled covariance matrix.我知道您可以使用未缩放的协方差矩阵的对角线元素的平方根手动计算 SE。 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.在使用不同方法和附加信息的另一个模型中使用来自一个模型的估计(和反向计算)SE 似乎不太可能奏效。

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.但是,如果它确实适用于模拟数据,那么它会让您更有信心相信它对真实数据是真实的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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