Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ok-landscape
GitHub Repository: Ok-landscape/computational-pipeline
Path: blob/main/latex-templates/templates/knitr/clinical_report.Rnw
51 views
unlisted
1
\documentclass{article}
2
\usepackage{geometry}
3
\usepackage{graphicx}
4
\usepackage{hyperref}
5
\usepackage{booktabs} % Required for xtable aesthetics
6
7
\title{Phase III Clinical Trial Analysis}
8
\author{Bioinformatics Division}
9
10
\begin{document}
11
\maketitle
12
13
\section{Statistical Analysis Protocol}
14
15
We investigate the efficacy of Treatment A vs. Placebo. The analysis is performed using R version \Sexpr{getRversion()}.
16
17
% Global Chunk Options
18
% echo=TRUE: Show R code in the document (transparency)
19
% warning=FALSE: Suppress warning messages in final PDF
20
% dev='pdf': Generate high-quality vector graphics
21
<<setup, include=FALSE>>=
22
library(knitr)
23
library(ggplot2)
24
library(xtable)
25
opts_chunk$set(echo=TRUE, warning=FALSE, message=FALSE, dev='pdf', fig.width=6, fig.height=4)
26
@
27
28
\section{Data Ingestion and Summary}
29
30
<<data_load, results='asis'>>=
31
# Simulate Clinical Data
32
set.seed(2024)
33
n <- 50
34
df <- data.frame(
35
id = 1:(2*n),
36
group = factor(rep(c("Placebo", "Treatment"), each=n)),
37
recovery_days = c(rnorm(n, mean=14, sd=3), rnorm(n, mean=10, sd=2.5))
38
)
39
40
# Descriptive Statistics Table
41
summary_stats <- aggregate(recovery_days ~ group, data=df, FUN=function(x) c(Mean=mean(x), SD=sd(x)))
42
summary_stats <- do.call(data.frame, summary_stats) # Flatten structure
43
44
# Print as LaTeX table using xtable
45
print(xtable(summary_stats, caption="Descriptive Statistics by Group"),
46
booktabs=TRUE, include.rownames=FALSE)
47
@
48
49
The table above is generated dynamically. If the underlying dataset \texttt{df} changes, the table updates automatically without manual re-formatting.
50
51
\section{Hypothesis Testing and Visualization}
52
53
We perform an independent t-test to compare the groups.
54
55
<<ttest, echo=FALSE>>=
56
test_result <- t.test(recovery_days ~ group, data=df)
57
pval <- test_result$p.value
58
@
59
60
The t-test yields a p-value of \Sexpr{format.pval(pval, eps=0.001)}.
61
\Sexpr{ifelse(pval < 0.05, "This indicates a statistically significant difference.", "This result is not significant.")}
62
63
<<boxplot, fig.cap="Distribution of Recovery Days by Treatment Group">>=
64
ggplot(df, aes(x=group, y=recovery_days, fill=group)) +
65
geom_boxplot(alpha=0.7) +
66
geom_jitter(width=0.2, alpha=0.5) +
67
theme_minimal() +
68
labs(y="Days to Recovery", x="Study Group") +
69
scale_fill_brewer(palette="Pastel1")
70
@
71
72
\end{document}
73
74