2012-12-10 94 views
2

我使用memisc包中的mtable取得了一些成功,可以並行排列多個迴歸結果(APSR樣式),但我無法獲得相同的結果命令可以從MASS包中選擇lrm(),包可以從robustbase包中選擇。迴歸表R

偉大工程:

lm0 <- lm(sr ~ pop15 + pop75,    data = LifeCycleSavings) 
lm1 <- lm(sr ~     dpi + ddpi, data = LifeCycleSavings) 
lm2 <- lm(sr ~ pop15 + pop75 + dpi + ddpi, data = LifeCycleSavings) 

mtable123 <- mtable("Model 1"=lm0,"Model 2"=lm1,"Model 3"=lm2) 

未能在mtable()命令("Error in qt(p, df, lower.tail, log.p): Non-numeric argument to mathematical function")

rlm0 <- rlm(sr ~ pop15 + pop75,    data = LifeCycleSavings) 
rlm1 <- rlm(sr ~     dpi + ddpi, data = LifeCycleSavings) 
rlm2 <- rlm(sr ~ pop15 + pop75 + dpi + ddpi, data = LifeCycleSavings) 

mtable123 <- mtable("Model 1"=rlm0, "Model 2"=rlm1, "Model 3"=rlm2) 

未能在mtable()命令():

lmrob0 <- lmrob(sr ~ pop15 + pop75,    data = LifeCycleSavings) 
lmrob1 <- lmrob(sr ~     dpi + ddpi, data = LifeCycleSavings) 
lmrob2 <- lmrob(sr ~ pop15 + pop75 + dpi + ddpi, data = LifeCycleSavings) 

mtable123 <- mtable("Model 1"=lmrob0, "Model 2"=lmrob1, "Model 3"=lmrob2) 

我打開的建議不涉及mtable,但我是羅用於純文本或製表符分隔的輸出(換句話說,不是LaTeX)。

回答

3

?getSummarymemisc包的文檔描述瞭如何可以延長mtable功能要在其他模型類型使用。

特別是,您需要爲getSummary創建適當的方法,然後使用setSummaryTemplate創建摘要模板。所以,舉個例子,像這樣的工作:

getSummary.rlm <- function(obj, alpha = 0.5,...){ 
    obj_summary <- summary(obj) 

    coefficients <- cbind(coef(obj_summary),dt(coefficients[,3],df = obj_summary$df)) 
    #You can add the CI code yourself, this is a placeholder: 
    coefficients <- cbind(coefficients,matrix(NA,nrow(coefficients),2)) 
    colnames(coefficients) <- c('est','se','stat','p','lwr','upr') 

    sumstat <- c(sigma = obj_summary$sigma,df = obj_summary$df[2],stddev = obj_summary$stddev) 

    return(list(coef = coefficients,sumstat = sumstat)) 
} 

setSummaryTemplate(rlm = c(sigma = "($sigma:#)",df = "($df:#)",stddev = "($stddev:#)")) 

mtable123 <- mtable("Model 1"=rlm0,"Model 2"=rlm1,"Model 3"=rlm2) 
mtable123 

Calls: 
Model 1: NULL 
Model 2: NULL 
Model 3: NULL 

======================================= 
      Model 1 Model 2 Model 3 
--------------------------------------- 
(Intercept) 28.528* 6.497** 28.945** 
      (7.535) (1.225) (7.602) 
pop15  -0.434**   -0.473** 
      (0.149)   (0.150) 
pop75  -1.595   -1.655 
      (1.059)   (1.120) 
dpi     0.001* -0.000 
         (0.001) (0.001) 
ddpi     0.462 0.385 
         (0.206) (0.203) 
--------------------------------------- 
sigma   3.739 4.383 3.523 
df   47.000 47.000 45.000 
stddev   3.998 4.098 3.931 
======================================= 
+0

哇 - 這正是我需要的!感謝代碼。 一個問題:第4行應該是「係數< - cbind(coef(obj_summary),dt(coef(obj_summary)[,3],df = obj_summary $ df))」,對嗎? –