2017-03-19 1 views
0

R에서 summary 함수를 사용할 때 거기에 전달할 수있는 변수의 서브 세트 만 표시 할 수있는 옵션이 있습니까?R에서 변수의 서브 세트 얻기

필자는 예를 들어 패널 회귀 분석을 실시했는데 몇 가지 설명 변수가 있으며 계수가없는 많은 더미 변수가 있습니다. 이 작업을 수행하는 간단한 방법이 있지만 함수 설명서에서 찾을 수 없습니다. 당신이 실행 한 회귀 가정 덕분에

+1

만, 열 1, 3, 5를 원하는'요약을 사용하는 경우 (DF [, C는 (1,3,5)])는'G5W @ – G5W

+0

그럴 수 없어 그 구문을 작동 시키십시오. " 'closure'타입의 객체는 서브 세트화할 수 없습니다." – noumenal

+1

'summary' 객체는 데이터 프레임이 아니므로 그 방식으로 서브 세트 될 수 없습니다. – neilfws

답변

2

그것은 설명서에,하지만 당신은 summary.plm의 associacted print 방법을 찾아해야합니다. 인수는 subset입니다. 다음 예제로 사용

library(plm) 
data("Grunfeld", package = "plm") 
mod <- plm(inv ~ value + capital, data = Grunfeld) 
print(summary(mod), subset = c("capital")) 
2

기본 lm() 모델의 summary()으로 유사하게 동작합니다

# set up data 
x <- 1:100 * runif(100, .01, .02) 
y <- 1:100 * runif(100, .01, .03) 


# run a very basic linear model 
mylm <- lm(x ~ y) 
summary(mylm) 


# we can save summary of our linear model as a variable 
mylm_summary <- summary(mylm) 

# we can then isolate coefficients from this summary (summary is just a list) 
mylm_summary$coefficients 

#output: 
Estimate Std. Error t value  Pr(>|t|) 
(Intercept) 0.2007199 0.04352267 4.611846 1.206905e-05 
y   0.5715838 0.03742379 15.273273 1.149594e-27 


# note that the class of this "coefficients" object is a matrix 
class(mylm_summ$coefficients) 

# output 
[1] "matrix" 

# we can convert that matrix into a data frame so it is easier to work with and subset 
mylm_df_coefficients <- data.frame(mylm_summary$coefficients)