【发布时间】:2016-07-10 13:16:16
【问题描述】:
我正在尝试使用 R、Sweave 和 Latex 将我的 survdiff 打印到 pdf 中。
我正在复制下面的所有相关代码,但这是我需要打印出来的部分:
N Observed Expected (O-E)^2/E (O-E)^2/V
male=0 10 3 8.57 3.624 4.67
male=1 65 48 42.43 0.732 4.67
Chisq= 4.7 on 1 degrees of freedom, p= 0.0306
这里的代码几乎可以让我到达我想要的地方:
s.male <- survfit( Surv(futime, status)~ strata(male), shou3, conf.type="log-log")
plot(s.male, lty=c(1,3), xlab="Time", ylab="Survival Probability")
legend(30, 1.1, c("Female","Male")
, lty=c(1,3) )
sma <- print.data.frame(survdiff(Surv(futime, status) ~ male
, data=shou3, rho=0))
sma2 <- print.data.frame(sma, digits = 2)
> sma2
Call:
survdiff(formula = Surv(futime, status) ~ male, data = shou3,
rho = 0)
N Observed Expected (O-E)^2/E (O-E)^2/V
male=0 10 3 8.57 3.624 4.67
male=1 65 48 42.43 0.732 4.67
Chisq= 4.7 on 1 degrees of freedom, p= 0.0306
这就是我正在尝试但没有做任何事情的所有内容。
<<results=tex, echo=FALSE>>=
latex(print(sma), file='', landscape=TRUE, round=1)
#latex(sma2, file = " ")
#latex(print.data.frame(sma2, cdec = 2, file=''))
#malesd <- survdiff(as.formula(sma$call$formula))
#latex(print(sma2, latex=TRUE, coefs=FALSE, file = " "))
#latex(sma2, file = " ")
# , cdec=c(0,0,2,2,2), na.blank=TRUE, booktabs=TRUE, table.env=FALSE, center="none", file="", title="")
@
我似乎无法从对象中取出 (OE)^2/E (OE)^2/V 元素,也无法取出我想要的 Chisq 线(我试过 cbind /rbind)。我正在使用 R Studio,它是一个 .rnw 文件。
【问题讨论】: