Path: blob/main/latex-templates/templates/knitr/clinical_report.tex
51 views
unlisted
\documentclass{article}\usepackage[]{graphicx}\usepackage[]{xcolor}1% maxwidth is the original width if it is less than linewidth2% otherwise use linewidth (to make sure the graphics do not exceed the margin)3\makeatletter4\def\maxwidth{ %5\ifdim\Gin@nat@width>\linewidth6\linewidth7\else8\Gin@nat@width9\fi10}11\makeatother1213\definecolor{fgcolor}{rgb}{0.345, 0.345, 0.345}14\newcommand{\hlnum}[1]{\textcolor[rgb]{0.686,0.059,0.569}{#1}}%15\newcommand{\hlsng}[1]{\textcolor[rgb]{0.192,0.494,0.8}{#1}}%16\newcommand{\hlcom}[1]{\textcolor[rgb]{0.678,0.584,0.686}{\textit{#1}}}%17\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}%18\newcommand{\hldef}[1]{\textcolor[rgb]{0.345,0.345,0.345}{#1}}%19\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.161,0.373,0.58}{\textbf{#1}}}%20\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.69,0.353,0.396}{#1}}%21\newcommand{\hlkwc}[1]{\textcolor[rgb]{0.333,0.667,0.333}{#1}}%22\newcommand{\hlkwd}[1]{\textcolor[rgb]{0.737,0.353,0.396}{\textbf{#1}}}%23\let\hlipl\hlkwb2425\usepackage{framed}26\makeatletter27\newenvironment{kframe}{%28\def\at@end@of@kframe{}%29\ifinner\ifhmode%30\def\at@end@of@kframe{\end{minipage}}%31\begin{minipage}{\columnwidth}%32\fi\fi%33\def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep34\colorbox{shadecolor}{##1}\hskip-\fboxsep35% There is no \\@totalrightmargin, so:36\hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%37\MakeFramed {\advance\hsize-\width38\@totalleftmargin\z@ \linewidth\hsize39\@setminipage}}%40{\par\unskip\endMakeFramed%41\at@end@of@kframe}42\makeatother4344\definecolor{shadecolor}{rgb}{.97, .97, .97}45\definecolor{messagecolor}{rgb}{0, 0, 0}46\definecolor{warningcolor}{rgb}{1, 0, 1}47\definecolor{errorcolor}{rgb}{1, 0, 0}48\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX4950\usepackage{alltt}51\usepackage{geometry}52\usepackage{graphicx}53\usepackage{hyperref}54\usepackage{booktabs} % Required for xtable aesthetics5556\title{Phase III Clinical Trial Analysis}57\author{Bioinformatics Division}58\IfFileExists{upquote.sty}{\usepackage{upquote}}{}59\begin{document}60\maketitle6162\section{Statistical Analysis Protocol}6364We investigate the efficacy of Treatment A vs. Placebo. The analysis is performed using R version 4.5.1.6566% Global Chunk Options67% echo=TRUE: Show R code in the document (transparency)68% warning=FALSE: Suppress warning messages in final PDF69% dev='pdf': Generate high-quality vector graphics707172\section{Data Ingestion and Summary}7374\begin{kframe}75\begin{alltt}76\hlcom{# Simulate Clinical Data}77\hlkwd{set.seed}\hldef{(}\hlnum{2024}\hldef{)}78\hldef{n} \hlkwb{<-} \hlnum{50}79\hldef{df} \hlkwb{<-} \hlkwd{data.frame}\hldef{(}80\hlkwc{id} \hldef{=} \hlnum{1}\hlopt{:}\hldef{(}\hlnum{2}\hlopt{*}\hldef{n),}81\hlkwc{group} \hldef{=} \hlkwd{factor}\hldef{(}\hlkwd{rep}\hldef{(}\hlkwd{c}\hldef{(}\hlsng{"Placebo"}\hldef{,} \hlsng{"Treatment"}\hldef{),} \hlkwc{each}\hldef{=n)),}82\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{))}83\hldef{)}8485\hlcom{# Descriptive Statistics Table}86\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)))}87\hldef{summary_stats} \hlkwb{<-} \hlkwd{do.call}\hldef{(data.frame, summary_stats)} \hlcom{# Flatten structure}8889\hlcom{# Print as LaTeX table using xtable}90\hlkwd{print}\hldef{(}\hlkwd{xtable}\hldef{(summary_stats,} \hlkwc{caption}\hldef{=}\hlsng{"Descriptive Statistics by Group"}\hldef{),}91\hlkwc{booktabs}\hldef{=}\hlnum{TRUE}\hldef{,} \hlkwc{include.rownames}\hldef{=}\hlnum{FALSE}\hldef{)}92\end{alltt}93\end{kframe}% latex table generated in R 4.5.1 by xtable 1.8-4 package94% Sat Nov 22 21:54:49 202595\begin{table}[ht]96\centering97\begin{tabular}{lrr}98\toprule99group & recovery\_days.Mean & recovery\_days.SD \\100\midrule101Placebo & 13.77 & 3.19 \\102Treatment & 9.76 & 2.48 \\103\bottomrule104\end{tabular}105\caption{Descriptive Statistics by Group}106\end{table}107108109The table above is generated dynamically. If the underlying dataset \texttt{df} changes, the table updates automatically without manual re-formatting.110111\section{Hypothesis Testing and Visualization}112113We perform an independent t-test to compare the groups.114115116117The t-test yields a p-value of < 0.001.118This indicates a statistically significant difference.119120\begin{knitrout}121\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}122\begin{alltt}123\hlkwd{ggplot}\hldef{(df,} \hlkwd{aes}\hldef{(}\hlkwc{x}\hldef{=group,} \hlkwc{y}\hldef{=recovery_days,} \hlkwc{fill}\hldef{=group))} \hlopt{+}124\hlkwd{geom_boxplot}\hldef{(}\hlkwc{alpha}\hldef{=}\hlnum{0.7}\hldef{)} \hlopt{+}125\hlkwd{geom_jitter}\hldef{(}\hlkwc{width}\hldef{=}\hlnum{0.2}\hldef{,} \hlkwc{alpha}\hldef{=}\hlnum{0.5}\hldef{)} \hlopt{+}126\hlkwd{theme_minimal}\hldef{()} \hlopt{+}127\hlkwd{labs}\hldef{(}\hlkwc{y}\hldef{=}\hlsng{"Days to Recovery"}\hldef{,} \hlkwc{x}\hldef{=}\hlsng{"Study Group"}\hldef{)} \hlopt{+}128\hlkwd{scale_fill_brewer}\hldef{(}\hlkwc{palette}\hldef{=}\hlsng{"Pastel1"}\hldef{)}129\end{alltt}130\end{kframe}\begin{figure}131\includegraphics[width=\maxwidth]{figure/boxplot-1} \caption[Distribution of Recovery Days by Treatment Group]{Distribution of Recovery Days by Treatment Group}\label{fig:boxplot}132\end{figure}133134\end{knitrout}135136\end{document}137138139