Parcourir la source

Adding selectValid

Andrej il y a 1 semaine
Parent
commit
39b4e849cd
2 fichiers modifiés avec 60 ajouts et 0 suppressions
  1. 29 0
      R/modifyData.R
  2. 31 0
      man/selectValid.Rd

+ 29 - 0
R/modifyData.R

@@ -21,3 +21,32 @@ sumWithNA<-function(df,var1='lesionmtv41',var2='metastasesmtv41',outVar='totalmt
       
 }
 
+#' Map variable time OS status to status at cutoff
+#'
+#' @param df data frame
+#' @param cutoff time instance where OS is evaluated, same units as timeVar
+#' @param timeVar name of column where times of status evaluation are recorded (from treatment start)
+#' @param osVar name of column with status at evaluation (1-alive/progress free, 2-censored, 3-dead/w/disease)
+#' @param targetVar name of target variable holding status at cutoff (0-dead, 1-alive, 2-censored)
+#'
+#' @return updated data frame with targetVar
+
+selectValid<-function(df,cutoff=2,timeVar='years_to_event',osVar='st_osMAP',targetVar='osAtCutoff'){
+   #if alive and ytoevent>c -> alive
+   #if censored and ytoe>c -> alive
+   #if dod and ytovent>c -> alive
+   df[,targetVar]=1
+
+
+
+   #if alive and ytoe<c -> censored
+   df[(df[,timeVar]<cutoff) & df[,osVar] == 1,targetVar]=2
+
+   #if censored and ytoe<c -> censored
+   df[df[,timeVar]<cutoff & df[,osVar] == 2,targetVar]=2
+
+   #if dod and ytovent<c -> dead
+   df[df[,timeVar]<cutoff & df[,osVar] == 3,targetVar]=0
+   df
+
+}

+ 31 - 0
man/selectValid.Rd

@@ -0,0 +1,31 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/modifyData.R
+\name{selectValid}
+\alias{selectValid}
+\title{Map variable time OS status to status at cutoff}
+\usage{
+selectValid(
+  df,
+  cutoff = 2,
+  timeVar = "years_to_event",
+  osVar = "st_osMAP",
+  targetVar = "osAtCutoff"
+)
+}
+\arguments{
+\item{df}{data frame}
+
+\item{cutoff}{time instance where OS is evaluated, same units as timeVar}
+
+\item{timeVar}{name of column where times of status evaluation are recorded (from treatment start)}
+
+\item{osVar}{name of column with status at evaluation (1-alive/progress free, 2-censored, 3-dead/w/disease)}
+
+\item{targetVar}{name of target variable holding status at cutoff (0-dead, 1-alive, 2-censored)}
+}
+\value{
+updated data frame with targetVar
+}
+\description{
+Map variable time OS status to status at cutoff
+}