-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathFTP_example.Rmd
111 lines (90 loc) · 4.23 KB
/
FTP_example.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
---
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 here
source("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 stats
table_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 wrapper
ddist <- datadist(melanoma)
options(datadist = "ddist")
# Do the cox regression model
# for melanoma specific death
msurv <- Surv(melanoma$time_years, melanoma$status=="Melanoma death")
fit <- cph(msurv ~ sex + age + ulcer + thickness, data=melanoma)
# Print the model
printCrudeAndAdjustedModel(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))
})
```