get_cumI=function(data,stratum){ fit <-survfit(Surv(phenos.CAD_censor_age,phenos.has_CAD)~1, data=data[data$Interaction==stratum]) cumulative_hazard <- fit$cumhaz[length(fit$cumhaz)] cum_haz_se=fit$std.err[length(fit$cumhaz)]return(list(ch=cumulative_hazard,se=cum_haz_se))}get_cumI(dyoung,stratum="low.(0,0.2]")
$ch
[1] 0.004524879
$se
[1] 0.001108599
Code
get_cumI(dyoung,stratum="high.(0.8,1]")
$ch
[1] 0.1415855
$se
[1] 0.006954524
Code
get_cumI(dmid,stratum="low.(0,0.2]")
$ch
[1] 0.008306283
$se
[1] 0.002032033
Code
get_cumI(dmid,stratum="high.(0.8,1]")
$ch
[1] 0.2695373
$se
[1] 0.05540406
Code
get_cumI(dold,stratum="low.(0,0.2]")
$ch
[1] 0.04594303
$se
[1] 0.0247146
Code
get_cumI(dold,stratum="high.(0.8,1]")
$ch
[1] 0.3675943
$se
[1] 0.1349052
Code
## to get standard erro# https://dominicmagirr.github.io/post/2022-01-18-be-careful-with-standard-errors-in-survival-survfit/### http://www.sthda.com/english/wiki/survival-analysis-basics# Get unique levels of the strata variablestrata_levels <-unique(dyoung$Interaction)# Loop through each level of the stratafor (strata_level inc("low.(0,0.2]","high.(0.8,1]")) {# Subset the survival object for the current strata levelstrata_surv <-survfit(Surv(phenos.CAD_censor_age,phenos.has_CAD)~1, data=dyoung[dyoung$Interaction==strata_level,])# Calculate the cumulative hazard cumhaz <--log(strata_surv$surv)[length(strata_surv$surv)] lower=-log(strata_surv$upper)[length(strata_surv$surv)] upper=-log(strata_surv$lower)[length(strata_surv$surv)]# Print the results for the current strata levelcat("Strata Level:", strata_level, "\n")cat("Cumulative Hazard:", cumhaz, "\n")cat("Cumulative Hazard Confidence Interval:", c(lower,upper), "\n\n")}
# Loop through each level of the stratafor (strata_level inc("low.(0,0.2]","high.(0.8,1]")) {# Subset the survival object for the current strata levelstrata_surv <-survfit(Surv(phenos.CAD_censor_age,phenos.has_CAD)~1, data=dold[dold$Interaction==strata_level,])# Calculate the cumulative hazard cumhaz <--log(strata_surv$surv)[length(strata_surv$surv)] fit=strata_surv lower=fit$cumhaz[length(fit$cumhaz)]-1.96*fit$std.chaz[length(fit$cumhaz)] upper=fit$cumhaz[length(fit$cumhaz)]+1.96*fit$std.chaz[length(fit$cumhaz)] lower2=-log(strata_surv$upper)[length(strata_surv$surv)] upper2=-log(strata_surv$lower)[length(strata_surv$surv)]# Print the results for the current strata levelcat("Strata Level:", strata_level, "\n")cat("Cumulative Hazard:", cumhaz, "\n")cat("Cumulative Hazard Confidence Interval symmetric:", c(lower,upper), "\n\n")cat("Cumulative Hazard Confidence Interval log:", c(lower2,upper2), "\n\n")}
#Among individuals with CAD <55 years, XXX (XXX%) had high (>20th # percentile) PRS and XXX (XXX%) had high (>20% estimated risk) PCE. dyoungevent=df[df$phenos.CAD_censor_age<55&df$phenos.has_CAD==1,]sum(dyoungevent$prs.r>0.80)
[1] 429
Code
t.test(dyoungevent$prs.r>0.80)
One Sample t-test
data: dyoungevent$prs.r > 0.8
t = 26.625, df = 1084, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
0.3662531 0.4245304
sample estimates:
mean of x
0.3953917
One Sample t-test
data: dyoungevent$ascvd_10y_accaha_all > 20
t = 5.7395, df = 1084, p-value = 1.232e-08
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
0.01941036 0.03957582
sample estimates:
mean of x
0.02949309