Path: blob/main/latex-templates/templates/knitr/clinical_report.Rnw
51 views
unlisted
\documentclass{article}1\usepackage{geometry}2\usepackage{graphicx}3\usepackage{hyperref}4\usepackage{booktabs} % Required for xtable aesthetics56\title{Phase III Clinical Trial Analysis}7\author{Bioinformatics Division}89\begin{document}10\maketitle1112\section{Statistical Analysis Protocol}1314We investigate the efficacy of Treatment A vs. Placebo. The analysis is performed using R version \Sexpr{getRversion()}.1516% Global Chunk Options17% echo=TRUE: Show R code in the document (transparency)18% warning=FALSE: Suppress warning messages in final PDF19% dev='pdf': Generate high-quality vector graphics20<<setup, include=FALSE>>=21library(knitr)22library(ggplot2)23library(xtable)24opts_chunk$set(echo=TRUE, warning=FALSE, message=FALSE, dev='pdf', fig.width=6, fig.height=4)25@2627\section{Data Ingestion and Summary}2829<<data_load, results='asis'>>=30# Simulate Clinical Data31set.seed(2024)32n <- 5033df <- data.frame(34id = 1:(2*n),35group = factor(rep(c("Placebo", "Treatment"), each=n)),36recovery_days = c(rnorm(n, mean=14, sd=3), rnorm(n, mean=10, sd=2.5))37)3839# Descriptive Statistics Table40summary_stats <- aggregate(recovery_days ~ group, data=df, FUN=function(x) c(Mean=mean(x), SD=sd(x)))41summary_stats <- do.call(data.frame, summary_stats) # Flatten structure4243# Print as LaTeX table using xtable44print(xtable(summary_stats, caption="Descriptive Statistics by Group"),45booktabs=TRUE, include.rownames=FALSE)46@4748The table above is generated dynamically. If the underlying dataset \texttt{df} changes, the table updates automatically without manual re-formatting.4950\section{Hypothesis Testing and Visualization}5152We perform an independent t-test to compare the groups.5354<<ttest, echo=FALSE>>=55test_result <- t.test(recovery_days ~ group, data=df)56pval <- test_result$p.value57@5859The t-test yields a p-value of \Sexpr{format.pval(pval, eps=0.001)}.60\Sexpr{ifelse(pval < 0.05, "This indicates a statistically significant difference.", "This result is not significant.")}6162<<boxplot, fig.cap="Distribution of Recovery Days by Treatment Group">>=63ggplot(df, aes(x=group, y=recovery_days, fill=group)) +64geom_boxplot(alpha=0.7) +65geom_jitter(width=0.2, alpha=0.5) +66theme_minimal() +67labs(y="Days to Recovery", x="Study Group") +68scale_fill_brewer(palette="Pastel1")69@7071\end{document}727374