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.tex
51 views
unlisted
1
\documentclass{article}\usepackage[]{graphicx}\usepackage[]{xcolor}
2
% maxwidth is the original width if it is less than linewidth
3
% otherwise use linewidth (to make sure the graphics do not exceed the margin)
4
\makeatletter
5
\def\maxwidth{ %
6
\ifdim\Gin@nat@width>\linewidth
7
\linewidth
8
\else
9
\Gin@nat@width
10
\fi
11
}
12
\makeatother
13
14
\definecolor{fgcolor}{rgb}{0.345, 0.345, 0.345}
15
\newcommand{\hlnum}[1]{\textcolor[rgb]{0.686,0.059,0.569}{#1}}%
16
\newcommand{\hlsng}[1]{\textcolor[rgb]{0.192,0.494,0.8}{#1}}%
17
\newcommand{\hlcom}[1]{\textcolor[rgb]{0.678,0.584,0.686}{\textit{#1}}}%
18
\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}%
19
\newcommand{\hldef}[1]{\textcolor[rgb]{0.345,0.345,0.345}{#1}}%
20
\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.161,0.373,0.58}{\textbf{#1}}}%
21
\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.69,0.353,0.396}{#1}}%
22
\newcommand{\hlkwc}[1]{\textcolor[rgb]{0.333,0.667,0.333}{#1}}%
23
\newcommand{\hlkwd}[1]{\textcolor[rgb]{0.737,0.353,0.396}{\textbf{#1}}}%
24
\let\hlipl\hlkwb
25
26
\usepackage{framed}
27
\makeatletter
28
\newenvironment{kframe}{%
29
\def\at@end@of@kframe{}%
30
\ifinner\ifhmode%
31
\def\at@end@of@kframe{\end{minipage}}%
32
\begin{minipage}{\columnwidth}%
33
\fi\fi%
34
\def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
35
\colorbox{shadecolor}{##1}\hskip-\fboxsep
36
% There is no \\@totalrightmargin, so:
37
\hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
38
\MakeFramed {\advance\hsize-\width
39
\@totalleftmargin\z@ \linewidth\hsize
40
\@setminipage}}%
41
{\par\unskip\endMakeFramed%
42
\at@end@of@kframe}
43
\makeatother
44
45
\definecolor{shadecolor}{rgb}{.97, .97, .97}
46
\definecolor{messagecolor}{rgb}{0, 0, 0}
47
\definecolor{warningcolor}{rgb}{1, 0, 1}
48
\definecolor{errorcolor}{rgb}{1, 0, 0}
49
\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX
50
51
\usepackage{alltt}
52
\usepackage{geometry}
53
\usepackage{graphicx}
54
\usepackage{hyperref}
55
\usepackage{booktabs} % Required for xtable aesthetics
56
57
\title{Phase III Clinical Trial Analysis}
58
\author{Bioinformatics Division}
59
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
60
\begin{document}
61
\maketitle
62
63
\section{Statistical Analysis Protocol}
64
65
We investigate the efficacy of Treatment A vs. Placebo. The analysis is performed using R version 4.5.1.
66
67
% Global Chunk Options
68
% echo=TRUE: Show R code in the document (transparency)
69
% warning=FALSE: Suppress warning messages in final PDF
70
% dev='pdf': Generate high-quality vector graphics
71
72
73
\section{Data Ingestion and Summary}
74
75
\begin{kframe}
76
\begin{alltt}
77
\hlcom{# Simulate Clinical Data}
78
\hlkwd{set.seed}\hldef{(}\hlnum{2024}\hldef{)}
79
\hldef{n} \hlkwb{<-} \hlnum{50}
80
\hldef{df} \hlkwb{<-} \hlkwd{data.frame}\hldef{(}
81
\hlkwc{id} \hldef{=} \hlnum{1}\hlopt{:}\hldef{(}\hlnum{2}\hlopt{*}\hldef{n),}
82
\hlkwc{group} \hldef{=} \hlkwd{factor}\hldef{(}\hlkwd{rep}\hldef{(}\hlkwd{c}\hldef{(}\hlsng{"Placebo"}\hldef{,} \hlsng{"Treatment"}\hldef{),} \hlkwc{each}\hldef{=n)),}
83
\hlkwc{recovery_days} \hldef{=} \hlkwd{c}\hldef{(}\hlkwd{rnorm}\hldef{(n,} \hlkwc{mean}\hldef{=}\hlnum{14}\hldef{,} \hlkwc{sd}\hldef{=}\hlnum{3}\hldef{),} \hlkwd{rnorm}\hldef{(n,} \hlkwc{mean}\hldef{=}\hlnum{10}\hldef{,} \hlkwc{sd}\hldef{=}\hlnum{2.5}\hldef{))}
84
\hldef{)}
85
86
\hlcom{# Descriptive Statistics Table}
87
\hldef{summary_stats} \hlkwb{<-} \hlkwd{aggregate}\hldef{(recovery_days} \hlopt{~} \hldef{group,} \hlkwc{data}\hldef{=df,} \hlkwc{FUN}\hldef{=}\hlkwa{function}\hldef{(}\hlkwc{x}\hldef{)} \hlkwd{c}\hldef{(}\hlkwc{Mean}\hldef{=}\hlkwd{mean}\hldef{(x),} \hlkwc{SD}\hldef{=}\hlkwd{sd}\hldef{(x)))}
88
\hldef{summary_stats} \hlkwb{<-} \hlkwd{do.call}\hldef{(data.frame, summary_stats)} \hlcom{# Flatten structure}
89
90
\hlcom{# Print as LaTeX table using xtable}
91
\hlkwd{print}\hldef{(}\hlkwd{xtable}\hldef{(summary_stats,} \hlkwc{caption}\hldef{=}\hlsng{"Descriptive Statistics by Group"}\hldef{),}
92
\hlkwc{booktabs}\hldef{=}\hlnum{TRUE}\hldef{,} \hlkwc{include.rownames}\hldef{=}\hlnum{FALSE}\hldef{)}
93
\end{alltt}
94
\end{kframe}% latex table generated in R 4.5.1 by xtable 1.8-4 package
95
% Sat Nov 22 21:54:49 2025
96
\begin{table}[ht]
97
\centering
98
\begin{tabular}{lrr}
99
\toprule
100
group & recovery\_days.Mean & recovery\_days.SD \\
101
\midrule
102
Placebo & 13.77 & 3.19 \\
103
Treatment & 9.76 & 2.48 \\
104
\bottomrule
105
\end{tabular}
106
\caption{Descriptive Statistics by Group}
107
\end{table}
108
109
110
The table above is generated dynamically. If the underlying dataset \texttt{df} changes, the table updates automatically without manual re-formatting.
111
112
\section{Hypothesis Testing and Visualization}
113
114
We perform an independent t-test to compare the groups.
115
116
117
118
The t-test yields a p-value of < 0.001.
119
This indicates a statistically significant difference.
120
121
\begin{knitrout}
122
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
123
\begin{alltt}
124
\hlkwd{ggplot}\hldef{(df,} \hlkwd{aes}\hldef{(}\hlkwc{x}\hldef{=group,} \hlkwc{y}\hldef{=recovery_days,} \hlkwc{fill}\hldef{=group))} \hlopt{+}
125
\hlkwd{geom_boxplot}\hldef{(}\hlkwc{alpha}\hldef{=}\hlnum{0.7}\hldef{)} \hlopt{+}
126
\hlkwd{geom_jitter}\hldef{(}\hlkwc{width}\hldef{=}\hlnum{0.2}\hldef{,} \hlkwc{alpha}\hldef{=}\hlnum{0.5}\hldef{)} \hlopt{+}
127
\hlkwd{theme_minimal}\hldef{()} \hlopt{+}
128
\hlkwd{labs}\hldef{(}\hlkwc{y}\hldef{=}\hlsng{"Days to Recovery"}\hldef{,} \hlkwc{x}\hldef{=}\hlsng{"Study Group"}\hldef{)} \hlopt{+}
129
\hlkwd{scale_fill_brewer}\hldef{(}\hlkwc{palette}\hldef{=}\hlsng{"Pastel1"}\hldef{)}
130
\end{alltt}
131
\end{kframe}\begin{figure}
132
\includegraphics[width=\maxwidth]{figure/boxplot-1} \caption[Distribution of Recovery Days by Treatment Group]{Distribution of Recovery Days by Treatment Group}\label{fig:boxplot}
133
\end{figure}
134
135
\end{knitrout}
136
137
\end{document}
138
139