![](/img/trans.png)
[英]is there any way to calculate f-squared (as an effect size) for a predictor within an lm() multiple linear regression model?
[英]estimate of the variance of estimator for the effect of a predictor variable in a multiple linear regression model in R
bweight gestwks hyp sex
1 2974 38.5200004577637 0 female
2 3270 NA 0 male
3 2620 38.150001525878899 0 female
4 3751 39.799999237060497 0 male
5 3200 38.889999389648402 1 male
6 3673 40.970001220703097 0 female
体重=婴儿体重
gestwks=周妊娠期
hyp=母体高血压的存在
性别=婴儿的性别
我有这个示例,我用以下代码创建了一个多元线性回归模型:
lm2 = lm(bweight ~ gestwks + hyp + male)
其中,男性和女性是男性为 1,女性为 0 的向量。
如何找到误差 sigma^2 方差的无偏估计? 是不是代码:
summary(lm2)$sigma^2
会给我我正在寻找的答案吗?
另外,我如何找到对高血压影响的估计量方差的估计值。
所以,假设我有高血压的存在会影响婴儿的体重 -200(即高血压增加 1 个单位会导致平均体重下降 200)。 对高血压影响的估计量方差的估计值是多少?
您的示例数据:
df = structure(list(bweight = c(2974L, 3270L, 2620L, 3751L, 3200L,
3673L), gestwks = c(38.5200004577637, NA, 38.1500015258789, 39.7999992370605,
38.8899993896484, 40.9700012207031), hyp = c(0L, 0L, 0L, 0L,
1L, 0L), sex = structure(c(1L, 2L, 1L, 2L, 2L, 1L), .Label = c("female",
"male"), class = "factor"), male = c(0, 1, 0, 1, 1, 0)), row.names = c("1",
"2", "3", "4", "5", "6"), class = "data.frame")
df$male = as.numeric(df$sex=="male")
lm2 = lm(bweight ~ gestwks + hyp + male,data=df)
你想要的是方差-协方差矩阵:
vcov(lm2)
(Intercept) gestwks hyp male
(Intercept) 8615153.6 -219476.110 -199723.227 119995.418
gestwks -219476.1 5596.976 5093.248 -3283.549
hyp -199723.2 5093.248 57215.841 -29278.523
male 119995.4 -3283.549 -29278.523 36980.334
对角线是每个估计量的方差,如果你取平方根,你会得到标准误差和摘要:
sqrt(diag(vcov(lm2)))
(Intercept) gestwks hyp male
2935.15819 74.81294 239.19833 192.30271
summary(lm2)
Call:
lm(formula = bweight ~ gestwks + hyp + male, data = df)
Residuals:
1 3 4 5 6
1.218e+02 -1.058e+02 0.000e+00 7.105e-15 -1.598e+01
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -10304.13 2935.16 -3.511 0.177
gestwks 341.55 74.81 4.565 0.137
hyp -240.19 239.20 -1.004 0.499
male 461.63 192.30 2.401 0.251
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.