2011-05-03 2 views
0

요약에서 factornames를 삭제하는 방법을 궁금합니다. 예를 들어 나는 단위 성 (gender)이 단위 (M, W)로 있습니다.회귀 요약에서 factornames를 삭제하는 방법 R

genderM 

하지만 제가보고 싶은 것은 단지

M 

이 계산할 때 factornames 없애 R을 명령 할 수있다 : 내가 요약을 인쇄 할 때 변수의 이름입니다 선형 모델의 요약?

+2

예. 적절한 요약 기능 (예 : lm의 경우 summary.lm)을 적용하면 요소 이름이 아닌 레벨 만 인쇄 할 수 있습니다. 그러나 변수 color.mother와 color.child (레벨이 흰색과 갈색 모두)가 있으면 아이디어를 다시 생각해 볼 수 있습니다. R의 대부분의 디자인 선택은 꽤 좋은 이유가 있습니다. –

답변

0

:

outp <- summary(fit) 
attr(outp$coefficients, "dimnames")[[1]][2] <- levels(group)[2] 
outp 

결과 :

> outp 

Call: 
lm(formula = weight ~ group) 

Residuals: 
    Min  1Q Median  3Q  Max 
-1.0710 -0.4938 0.0685 0.2462 1.3690 

Coefficients: 
      Estimate Std. Error t value Pr(>|t|)  
(Intercept) 5.0320  0.2202 22.850 9.55e-15 *** 
Trt   -0.3710  0.3114 -1.191 0.249  
--- 
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.6964 on 18 degrees of freedom 
Multiple R-squared: 0.07308, Adjusted R-squared: 0.02158 
F-statistic: 1.419 on 1 and 18 DF, p-value: 0.249 
3

@Joris Meys는 매우 합리적인 충고에 유의할 수 있습니다. (. 사실, 난 당신이 제안) 또는 당신은 regexcapture.output의 비트와 함께 미봉책 약간의 해결 방법을 사용할 수 있습니다

  1. 잡아 summary.lm의 결과 사용 : 조작을 위해 지금

    # Set up data and fit model 
    ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) 
    trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69) 
    group <- gl(2,10,20, labels=c("Ctl","Trt")) 
    weight <- c(ctl, trt) 
    fit <- lm(weight ~ group) 
    

    capture.output

  2. 사용 gsub은 요인 수준의 각 발생을 대체하는

코드 :

# Capture output 
sfit <- capture.output(print(summary(fit))) 

gsub("groupTrt", "Trt  ", sfit) 

결과 :이 (Andrie의 예제)도 작동

[1] ""                
[2] "Call:"               
[3] "lm(formula = weight ~ group)"         
[4] ""                
[5] "Residuals:"              
[6] " Min  1Q Median  3Q  Max "      
[7] "-1.0710 -0.4938 0.0685 0.2462 1.3690 "      
[8] ""                
[9] "Coefficients:"             
[10] "   Estimate Std. Error t value Pr(>|t|) "   
[11] "(Intercept) 5.0320  0.2202 22.850 9.55e-15 ***"   
[12] "Trt   -0.3710  0.3114 -1.191 0.249 "   
[13] "---"                
[14] "Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 " 
[15] ""                
[16] "Residual standard error: 0.6964 on 18 degrees of freedom"  
[17] "Multiple R-squared: 0.07308,\tAdjusted R-squared: 0.02158 "  
[18] "F-statistic: 1.419 on 1 and 18 DF, p-value: 0.249 "    
[19] ""      
+0

고마워요! 이것은 나에게 매우 도움이된다! – user734124