2

我已经成功使用memisc包中的 mtable 到漂亮的打印结果(APSR 样式)并排几个回归,但是我无法让相同的命令适用lrm()MASS包中适合的模型和lmrob()robustbase包中。

效果很好:

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()在命令 ( "Error in UseMethod("getSummary"): no applicable method for 'getSummary' applied to an object of class "lmrob"")处失败:

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)。

4

1 回答 1

3

memisc?getSummary包中的文档描述了如何扩展该函数以用于其他模型类型。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 
=======================================
于 2012-12-10T19:54:37.567 回答