2012-06-19 5 views
20

에서 표준 오류 출력은 우리로부터 LM 객체 있고 난 함수 요약, 이름과 계수를 알고있는 표준 오류R : LM 객체

lm_aaa<- lm(aaa~x+y+z) 

을 추출 할. 그러나 요약은 수동으로 표준 오류에 액세스하는 유일한 방법 인 것 같습니다. 어떻게 출력 할 수 있습니까?

감사합니다.

답변

16

summary 기능은 단지 R 목록이다로부터의 출력. 따라서 모든 표준 목록 작업을 사용할 수 있습니다. 예를 들어 :

#some data (taken from Roland's example) 
x = c(1,2,3,4) 
y = c(2.1,3.9,6.3,7.8) 

#fitting a linear model 
fit = lm(y~x) 
m = summary(fit) 

m 개체 또는 목록 속성을 가지고 있습니다. 당신은 브래킷 또는 명명 된 접근 방식을 사용하여 액세스 할 수 있습니다

m$sigma 
m[[6]] 

편리한 기능에 관한 것입니다, str을 알고. 이 기능은 다른 사람이 지적했듯이 당신이

summary(lm_aaa)$coefficients[, 2] 

을 사용할 수 있습니다, 객체의 요약 속성이 제공하는 모든 매개 변수에 대한 표준 오차의 목록을 얻으려면

str(m) 
+0

그러나 @csgillespie가 말하는 것은 개별 계수의 표준 편차가 아니라 모델의 ** 잔류 표준 편차입니다. 'm $ sigma' 함수는'sigma (fit)'에 해당합니다. [here] (https://stat.ethz.ch/R-manual/R-devel/library/stats/html/sigma.html)를보십시오. 질문은 실제로 ** 개인 ** 계수의 표준 편차에 관한 것이라고 생각합니다. –

8
#some data 
x<-c(1,2,3,4) 
y<-c(2.1,3.9,6.3,7.8) 

#fitting a linear model 
fit<-lm(y~x) 

#look at the statistics summary 
summary(fit) 

#get the standard error of the slope 
se_slope<-summary(fit)$coef[[4]] 
#the index depends on the model and which se you want to extract 

#get the residual standard error 
rse<-summary(fit)$sigma 
11

을 즉, str(lm_aaa)은 말할 것이다 당신은 당신의 모델에서 추출 할 수있는 모든 정보를 거의 가지고 있습니다.

0

당신이 모델의 표준 오차/편차를 얻을 싶지는 않지만 대신 개별 계수의 표준 오차/편차의에 대한 자세한 내용은

# some data (taken from Roland's example) 
x = c(1, 2, 3, 4) 
y = c(2.1, 3.9, 6.3, 7.8) 

# fitting a linear model 
fit = lm(y ~ x) 

# get vector of all standard errors of the coefficients 
coef(summary(fit))[, "Std. Error"] 

를 사용하는 경우 모델의 표준 오차/편차는 here을 참조하십시오. 계수의 표준 오차/편차에 대한 자세한 내용은 here을 참조하십시오.