我使用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)。
答案 0 :(得分: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
=======================================