| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 | ---title: "A fast-track-publishing demo"output: Grmd::docx_document: fig_caption: TRUE force_captions: TRUE--- End section of methods====================== ```{r Data_prep, echo=FALSE, message=FALSE, warning=FALSE}# Moved this outside the document for easy of reading# I often have those sections in heresource("Setup_and_munge.R")``` ```{r Versions}info <- sessionInfo()r_ver <- paste(info$R.version$major, info$R.version$minor, sep=".")``` All analyses were performed using R (ver. `r r_ver`)[R Core Team, 2013] and packages rms (ver. `r info$otherPkgs$rms$Version`) [F. Harrell, 2014] for analysis, Gmisc for plot and table output (ver. `r info$otherPkgs$Gmisc$Version`), and knitr (ver `r info$otherPkgs$knitr$Version`) [Xie, 2013] for reproducible research. Results======= We found `r nrow(melanoma)` patients with malignant melanoma between the years `r paste(range(melanoma$year), collapse=" and ")`. Patients were followed until the end of 1977, the median follow-up time was `r sprintf("%.1f", median(melanoma$time_years))` years (range `r paste(sprintf("%.1f", range(melanoma$time_years)), collapse=" to ")` years). Males were more common than females and had also a higher mortality rate. ```{r Table1, cache=FALSE}table_data <- list()getT1Stat <- function(varname, digits=0){ getDescriptionStatsBy(melanoma[, varname], melanoma$status, add_total_col=TRUE, show_all_values=TRUE, hrzl_prop=TRUE, statistics=FALSE, html=TRUE, digits=digits)} # Get the basic statstable_data[["Sex"]] <- getT1Stat("sex")table_data[["Age<sup>†</sup>"]] <- getT1Stat("age")table_data[["Ulceration"]] <- getT1Stat("ulcer")table_data[["Thickness<sup>‡</sup>"]] <- getT1Stat("thickness", digits=1) mergeDesc(table_data) %>% htmlTable(header = gsub("[ ]*death", "", colnames(table_data[[1]])), # Add a column spanner cgroup = c("", "Death"), n.cgroup = c(2, 2), caption="Baseline characteristics", tfoot="<sup>†</sup> Age at the time of surgery. <sup>‡</sup> Tumour thickness, also known as Breslow thickness, measured in mm.", align="rrrr", css.rgroup = "") ``` Main results------------ ```{r C_and_A, results='asis'}label(melanoma$sex) <- "Sex"label(melanoma$age) <- "Age"label(melanoma$ulcer) <- "Ulceration"label(melanoma$thickness) <- "Breslow thickness" # Setup needed for the rms coxph wrapperddist <- datadist(melanoma)options(datadist = "ddist") # Do the cox regression model # for melanoma specific deathmsurv <- Surv(melanoma$time_years, melanoma$status=="Melanoma death")fit <- cph(msurv ~ sex + age + ulcer + thickness, data=melanoma) # Print the modelprintCrudeAndAdjustedModel(fit, desc_digits=0, caption="Adjusted and unadjusted estimates for melanoma specific death.", desc_column=TRUE, add_references=TRUE, ctable=TRUE) pvalues <- 1 - pchisq(coef(fit)^2/diag(vcov(fit)), df=1)``` After adjusting for the three variables, age, sex, tumor thickness and ulceration, only the latter two remained significant (p-value `r txtPval(pvalues["ulcer=Present"], lim.sig=10^-3)` and `r txtPval(pvalues["thickness"], lim.sig=10^-3)`), see table `r as.numeric(options("table_counter"))-1` and Fig. `r figCapNoNext()`. ```{r Regression_forestplot, fig.height=3, fig.width=5, out.height=300, out.width=500, dpi=300, fig.cap=figCapNo("A forest plot comparing the regression coefficients.")}# The output size can be fixed by out.width=625, out.height=375 but you loose the caption# I've adjusted the coefficient for age to be by forestplotRegrObj(update(fit, .~.-age+I(age/10)), order.regexps=c("Female", "age", "ulc", "thi"), box.default.size=.25, xlog=TRUE, zero=1, new_page=TRUE, clip=c(.5, 6), rowname.fn=function(x){ if (grepl("Female", x)) return("Female") if (grepl("Present", x)) return("Ulceration") if (grepl("age", x)) return("Age/10 years") return(capitalize(x))})``` ``` |