---
title: "Univariate_Multivariate"
author: "Pranjal Vaidya"
date: "`r Sys.Date()`"
linkcolor: blue
output:
  rmdformats::readthedown:
    highlight: kate
    number_sections: true
    code_folding: show
---

# Introduction 

Generating Radiomic Signature for predicting Disease-Free Survival in Early-Stage NSCLC.

# Data Load/Merge

Initial Setup and Package Loads in R 

Packages used for the analysis.
```{r initial_setup, cache=FALSE, message = FALSE, warning = FALSE}
library(glmnet);library(survival);library(survminer);library(readxl);library(ggplot2); library(GGally);library(knitr); library(rmdformats); library(magrittr);
library(skimr); library(Hmisc); library(Epi); library(vcd); library(tidyverse) 

source("Love-boost.R")

## Global options

options(max.print="75")
opts_chunk$set(comment=NA,
               message=FALSE,
               warning=FALSE)
opts_knit$set(width=75)


skimr::skim_with(numeric = list(hist = NULL),
                 integer = list(hist = NULL))
```

## Loading the Raw Data into R 

Loading raw dataset into R.

Training Data from CCF with minimum and max. survival time.
```{r}
train1 <- read.csv("dataset_train.csv")
train <- na.omit(train1)
train %>%
  select(QuRiS) %>%
  summary()
```

```{r}
variables <- c( "stage", "feature22")
formula <- sapply(variables,
                        function(x) as.formula(paste('Surv(time, status)~', x)))

univariate_analysis <- lapply(formula, function(x){coxph(x, data = train)})
# Extract data 
results <- lapply(univariate_analysis,
                       function(x){ 
                         x <- summary(x)
                         p.value<-signif(x$wald["pvalue"], digits=4)
                         beta<-signif(x$coef[1], digits=4);#coeficient beta
                         HR <-signif(x$coef[2], digits=4);#exp(beta)
                         HR.confint.lower <- signif(x$conf.int[,"lower .95"], 2)
                         HR.confint.upper <- signif(x$conf.int[,"upper .95"],2)
                         HR <- paste0(HR, " (", 
                                      HR.confint.lower, "-", HR.confint.upper, ")")
                         res<-c(beta, HR, p.value)
                         names(res)<-c("beta", "HR (95% CI for HR)", 
                                       "p.value")
                         return(res)
                       })
res <- t(as.data.frame(results, check.names = FALSE))
as.data.frame(res)
```




