harrelfe / rms

Regression Modeling Strategies
https://hbiostat.org/R/rms
Other
170 stars 48 forks source link

latex works for cph, generates .tex but does not work for anova tinytex or anova problem #120

Open stargorg opened 1 year ago

stargorg commented 1 year ago

My sample code is ....


title: "case_studycox_regression.R" author: "testing" date: "r Sys.time()" output: pdf_document: default

word_document: default

bookdown::html_document2: css: style.css toc: true number_sections: true code_folding: "hide" fig_caption: true


require(rms)

options(prType="latex")
getHdata(prostate)

levels(prostate$ekg)[levels(prostate$ekg) %in% c('old MI','recent MI')] <- 'MI'

#combine last 2 levels and use a new name

prostate$pf.coded <- as.integer(prostate$pf) 

levels(prostate$pf)<- c(levels(prostate$pf)[1:3],levels(prostate$pf[3]))

# combine last 2 levels

w <- transcan(~ sz + sg+ap+sbp + dbp + age+ wt + hg+ ekg + pf + bm + hx, imputed=TRUE, 
               data = prostate, pl=FALSE,pr=FALSE)
attach(prostate)
sz <- impute(w, sz, data=prostate)
sg <- impute(w, sg, data=prostate)
age <- impute(w, age, data=prostate)
wt <- impute(w, wt, data=prostate)
ekg <- impute(w, ekg, data=prostate)

dd <- datadist(prostate)
options(datadist="dd")

units(dtime) <- 'Month'
S <- Surv(dtime,status !='alive')

f <- cph(S~rx+rcs(age,4) + rcs(wt,4) + pf + hx +
           rcs(sbp,4) + rcs(dbp,4) + ekg + rcs(hg,4) + 
           rcs(sg,4)  + rcs(sz,4) + rcs(log(ap),4) + bm) #X matrix deemed to be singular; variable pf=confined to bed 

f <- cph(S~rx+rcs(age,4) + rcs(wt,4)  + hx +
           rcs(sbp,4) + rcs(dbp,4) + ekg + rcs(hg,4) + 
           rcs(sg,4)  + rcs(sz,4) + rcs(log(ap),4) + bm) #X matrix deemed to be singular; variable pf=confined to bed 

print(f,coefs = FALSE)

anova(f)

with the final anova statement I have a crash the message is ! Undefined control sequence. l.251 paste0(``\textbackslash Needspace{2in}\n '', caption), rowlabel = ````,

Error: LaTeX failed to compile ask_help.tex. See The R package tinytex - Helper Functions to Manage TinyTeX, and Compile LaTeX Documents - Yihui Xie | 谢益辉 for debugging tips. See ask_help.log for more info. Execution halted

=====

Without the anova statement the .rmd works well and produces a simple pdf with a table down the bottom.

I suspect that the anova command is calling something that is not defined. I have reinstalled my latex software but had the same fault. Are you able to help.

thanks Boffin