# Sample Information
```{r setup,include=FALSE, message=FALSE, warning=FALSE}
knitr::opts_chunk$set(cache=TRUE,echo = TRUE,warning = FALSE, message = FALSE,tinytex.verbose = TRUE, fig.align="center")
library(readxl)
library(DT)
#NPXZ #POPSID+Comparator+proteins+Y #12wk:POPSID+Comparator+proteins+Roche_PlGF+Roche_PAPP_A+Roche_AFP+Roche_hCGbeta+Y+(case_type for PE_and_FGR all GAs)
#NPX #POPSID+proteins+Y
load("Rdata/dl.npx.ISM2.RData")
#pops2 on NPXZ #POPSID+proteins+Y+(case_type for PE_and_FGR all GAs)
load("Rdata/dl.npxz5.pops2.ISM2.RData")
for (condition in names(dl.npxz5.pops2.ISM2)) {
for (time_point in names(dl.npxz5.pops2.ISM2[[condition]])) {
df <- dl.npxz5.pops2.ISM2[[condition]][[time_point]]
colnames(df)[ncol(df)] <- "y"
dl.npxz5.pops2.ISM2[[condition]][[time_point]] <- df}}
#########composite data
#pops on npxz #POPSID+Comparator+proteins+Roche_PlGF+Roche_PAPP_A+Roche_AFP+Roche_hCGbeta+Y
dl.npxz5.Roche.pops.composite.12wk<- read_excel("data/dl.npxz5.Roche.pops.composite.12wk.xlsx")
# Vector of biomarker names to winsorize
biomarkers <- c("Roche_PlGF", "Roche_PAPP_A", "Roche_AFP", "Roche_hCGbeta")
# Count values > 5 and < -5 for each biomarker
sapply(dl.npxz5.Roche.pops.composite.12wk[biomarkers], function(x) {
gt_5 <- sum(x > 5, na.rm = TRUE)
lt_neg5 <- sum(x < -5, na.rm = TRUE)
c(`>5` = gt_5, `<-5` = lt_neg5)})
# Apply winsorization at ±5
dl.npxz5.Roche.pops.composite.12wk[biomarkers] <- lapply(
dl.npxz5.Roche.pops.composite.12wk[biomarkers],
function(x) pmax(pmin(x, 5), -5))
#pops2 on npxz #POPSID+proteins+Y
dl.npxz5.pops2.composite.12wk<- read_excel("data/dl.npxz5.pops2.composite.12wk.xlsx")
```
All analyses should now focus on the following three outcomes:
1. Pure PE (i.e., PE only). Defined as any PE associated with preterm delivery plus severe de novo PE associated with delivery at term. Both confined to cases where the BW percentile was >10th.
2. Pure FGR (i.e., FGR only). Defined as birth weight <10th percentile associated with preterm delivery plus birth weight <3rd percentile at term. Both confined to cases where there was no diagnosis of preeclampsia (any form, severe or non-severe, de novo or superimposed).
3. PE with FGR. This is defined as any cases at any gestational age where there was any diagnosis of preeclampsia and where the birth weight was <10th percentile.
Each of the 3 outcomes is analysed in relation to the common comparison group which is limited to the women from the random sub-cohort who did not experience any PE or SGA/FGR.
## Data summary
### POPS
NB:Here PE_and_FGR means PE with FGR.
```{r data-zscore-summary-extract-pops, echo=FALSE, message=FALSE}
summary_table <- data.frame(
Condition = character(),
Time_Point = character(),
Rows = integer(),
Columns = integer(),
Y_0 = integer(),
Y_1 = integer(),
stringsAsFactors = FALSE
)
for (condition in names(dl.npx.ISM2)) {
time_point <- "12wk"
if (time_point %in% names(dl.npx.ISM2[[condition]])) {
df <- dl.npx.ISM2[[condition]][[time_point]]
dims <- dim(df)
if ("y" %in% colnames(df)) {
y_counts <- table(df$y)
y_0 <- ifelse("0" %in% names(y_counts), y_counts["0"], 0)
y_1 <- ifelse("1" %in% names(y_counts), y_counts["1"], 0)
} else {
y_0 <- 0
y_1 <- 0 }
summary_table <- rbind(summary_table, data.frame(
Condition = condition,
GA = time_point,
Subject = dims[1],
Controls = y_0,
Cases = y_1,
stringsAsFactors = FALSE )) }}
datatable(summary_table,
rownames = TRUE,
caption = "Summary of POPS serum explore (12wk only)",
options = list(
scrollX = TRUE,
scrollCollapse = TRUE,
pageLength = 5))
```
## POPS2
NB:Here PE_and_FGR means PE with FGR.
```{r data-zscore-summary-extract-pops2-rename_y, echo=FALSE, message=FALSE}
summary_table <- data.frame(
Condition = character(),
Time_Point = character(),
Rows = integer(),
Columns = integer(),
Y_0 = integer(),
Y_1 = integer(),
stringsAsFactors = FALSE)
time_point <- "12wk"
if (time_point %in% names(dl.npxz5.pops2.ISM2)) {
for (condition in names(dl.npxz5.pops2.ISM2[[time_point]])) {
df <- dl.npxz5.pops2.ISM2[[time_point]][[condition]]
dims <- dim(df)
if ("y" %in% colnames(df)) {
y_counts <- table(df$y)
y_0 <- ifelse("0" %in% names(y_counts), y_counts["0"], 0)
y_1 <- ifelse("1" %in% names(y_counts), y_counts["1"], 0)
} else {
y_0 <- 0
y_1 <- 0 }
summary_table <- rbind(summary_table, data.frame(
Condition = condition,
GA = time_point,
Subject = dims[1],
Controls = y_0,
Cases = y_1,
stringsAsFactors = FALSE )) }}
datatable(summary_table,
rownames = TRUE,
caption = "Summary of POPS2 serum explore (12wk only)",
options = list(
scrollX = TRUE,
scrollCollapse = TRUE,
pageLength = 5 ))
```
### Composite of three outcomes for POPS and POPS2
```{r data-zscore-summary-extract-pops-pops2-compostie, echo=FALSE, message=FALSE}
summary_12wk <- data.frame(
Outcome = character(),
GA = character(),
Subjects = integer(),
Cases = integer(),
Controls = integer(),
DAPs = integer(),
stringsAsFactors = FALSE)
for (condition in names(dl.npxz5.pops2.ISM2)) {
if ("12wk" %in% names(dl.npxz5.pops2.ISM2[[condition]])) {
df <- dl.npxz5.pops2.ISM2[[condition]][["12wk"]]
subjects <- nrow(df)
y_counts <- table(df$y)
cases <- ifelse("1" %in% names(y_counts), y_counts["1"], 0)
controls <- ifelse("0" %in% names(y_counts), y_counts["0"], 0)
summary_12wk <- rbind(summary_12wk, data.frame(
Outcome = condition,
GA = "12wk",
Subjects = subjects,
Cases = cases,
Controls = controls,
stringsAsFactors = FALSE )) }}
composite_data <- list(
"pops.composite.12wk" = dl.npxz5.Roche.pops.composite.12wk,
"pops2.composite.12wk" = dl.npxz5.pops2.composite.12wk)
for (name in names(composite_data)) {
df <- composite_data[[name]]
subjects <- nrow(df)
if ("y" %in% colnames(df)) {
y_counts <- table(df$y)
cases <- ifelse("1" %in% names(y_counts), y_counts["1"], 0)
controls <- ifelse("0" %in% names(y_counts), y_counts["0"], 0)
} else {
cases <- NA
controls <- NA }
summary_12wk <- rbind(summary_12wk, data.frame(
Outcome = name,
GA = "12wk",
Subjects = subjects,
Cases = cases,
Controls = controls,
stringsAsFactors = FALSE))}
datatable(summary_12wk, rownames = FALSE, caption = "Summary of composite data 12wk",
options = list(
scrollX = TRUE,
scrollCollapse = TRUE,
pageLength = 2))
```