leffgh
用summary 可以得到se , t*se好像就是要加减的那部分,
有没有直接获取置信区间的命令啊?
momozilla
好像没有。把coef和se读到两个vector里,自己计算,这很难么?
leffgh
怎样读se,不会
momozilla
查了一下,发现还真有个命令可以得到置信区间 confint
不好意思
我记错了,好像是不能直接得到se,得自己算
假定 g <- lm(a ~ b) 用如下方式得到se
sqrt(diag(summary(g)$cov.unsc))*summary(g)$sigma
leffgh
谢谢啊~~~
leffgh
summary(g)
Call:
lm(formula = b ~ a)
Residuals:
Min 1Q Median 3Q Max
-0.61200 -0.21137 -0.04017 0.20659 0.78499
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.40920 0.29306 11.633 2.71e-06 ***
a 0.04415 0.04723 0.935 0.377
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.429 on 8 degrees of freedom
Multiple R-Squared: 0.09846, Adjusted R-squared: -0.01423
F-statistic: 0.8737 on 1 and 8 DF, p-value: 0.3773
> class(summary(g)
+ )
[1] "summary.lm"
> colnames(summary(g))
NULL
> mode(summary(g))
[1] "list"
你怎么知道summary有summary(g)$cov.unsc,和 summary(g)$sigma 两个向量的?如果我要提取summary里面其他的数据,比如R-square怎么做啊?
momozilla
用 ? 查看帮助,有一个部分是 Values,重要的信息都在那儿有说明
用 names(summary(g)) 可以看到所以return的内容
因为R是面向对象的语言,所以类似于这种 fitted model object,都可能用names()查看的
leffgh
谢谢~~~
leffgh
names(summary(g))
[1] "call" "terms" "residuals" "coefficients"
[5] "aliased" "sigma" "df" "r.squared"
[9] "adj.r.squared" "fstatistic" "cov.unscaled"
> summary(g)$df
[1] 2 8 2
> summary(g)$sigma
[1] 0.4289894
summary(g)$df 出来3个数字,我的case加起来才10个,有一个自变量,模型的自由度是9才对,当中间那个8是残差自由度,那另外的两个2呢?
还有sigma,是什么的标准误么?但是我用summary(g)看,没有一个是0.4289894啊.
summary(g)
Call:
lm(formula = b ~ a)
Residuals:
Min 1Q Median 3Q Max
-0.61200 -0.21137 -0.04017 0.20659 0.78499
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.40920 0.29306 11.633 2.71e-06 ***
a 0.04415 0.04723 0.935 0.377
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.429 on 8 degrees of freedom
Multiple R-Squared: 0.09846, Adjusted R-squared: -0.01423
F-statistic: 0.8737 on 1 and 8 DF, p-value: 0.3773
随便弄的数字,所以r.square很低
leffgh
summary(g)$fstatistic
value numdf dendf
0.8736967 1.0000000 8.0000000
这个也看不懂,?summary也查不到这些东西.
TTG
[quote]引用第9楼leffgh于2007-08-22 19:26发表的“”:
summary(g)$fstatistic
value numdf dendf
0.8736967 1.0000000 8.0000000
这个也看不懂,?summary也查不到这些东西.[/quote]
这个是模型的F值,算出个p来,确定模型是否有意义。
TTG
还有你调残差自由度和其它的参数直接g$df就可以了,不要加summary这样就没那两个2了。