R/numericalDataRisk.fun.R

##############                  function that selects variables of interest and recodes some of them to numerical        #############################
#####################################################################################################################################################

numericalDataRisk.fun=function(dataset){
  library(car)
  ####recode treatment names####
  dataset$TRT01A<-as.numeric(dataset$TRT01A)
  dataset$TRT01A<-recode(dataset$TRT01A, "1='Avonex'; 2='Dimethyl fumarate';3='Dimethyl fumarate'; 4='Peginterferon Beta-1a';5='Peginterferon Beta-1a';6='Glatiramer acetate';7='Natalizumab';8='Natalizumab + Avonex';9='Placebo';10='Avonex'")
  
  ##################################HANDLING VARIABLES##############################################
  keep<-c("STUDYID","USUBJID","AGE","SEX","RACE","TRT01A","HEIGHTBL","WEIGHTBL","EDSSBL","ONSYRS","DIAGYRS",
          "DOMIHAND","RLPS3YR","RLPS1YR","TRELMOS", "MCDBL","PRMSGR","REGION","T25FWABL","NHPTMBL","NHPTDHBL","NHPTNHBL",
          "PASATABL","MSFCBL","GDLESBL","T2VOLBL","T1VOLBL","BVZBL","VFT100BL","VFT25BL",
          "VFT125BL","SFPCSBL","SFMCSBL","VISUALBL","BRAINBL","PYRAMIBL","SENSORBL","BOWLBLBL",
          "CEREBRBL","DISTWKBL","T25FWP1","NHPTMP1","NHPTDHP1","NHPTNHP1","PASATP1","T25FWPC","NHPTMPC","NHPTDHPC",
          "NHPTNHPC","PASATPC","RELAPSE1year","RELAPSE2year")
  MSrelapse<-dataset[,keep]
  
  ##################################HANDLING VARIABLES############################
  ###########################RECODE VARIABLES to numeric values############################
  MSrelapse$SEX<-recode(MSrelapse$SEX, "'M'=1; 'F'=0")
  MSrelapse$RACE<-recode(MSrelapse$RACE, "'WHITE'=1; 'NON-WHITE'=0")
  MSrelapse$DOMIHAND<-recode(MSrelapse$DOMIHAND, "'Left'=1;'LEFT'=1;  'Right'=0; 'RIGHT'=0;" )
  MSrelapse$DOMIHAND[which(MSrelapse$DOMIHAND=="")]<-NA
  MSrelapse$REGION<-recode(MSrelapse$REGION, "'Eastern Europe'=1;'India'=2;  'North America'=3; 'ROW'=4;'Western Europe'=5 " )
  mylevels <- c("< 100 METRES",
                ">= 100 METRES AND < 200 METRES", 
                ">= 200 METRES AND < 300 METRES", 
                ">= 300 METRES AND < 500 METRES", 
                ">= 500 METRES")
  
  MSrelapse$DISTWKBL<- as.numeric(factor(MSrelapse$DISTWKBL, levels=mylevels))
  MSrelapse$DISTWKBL<-as.factor(MSrelapse$DISTWKBL)
  ######delete variable RLPS1Y (all the information included in RLPS3Y)
  MSrelapse$RLPS1YR<-NULL
  #remove Sentinel study - Not included in AD data - Combination of therapies 
  MSrelapse$PRMSGR<-as.factor(MSrelapse$PRMSGR)
  MSrelapse$SENSORBL<-as.factor(MSrelapse$SENSORBL)
  MSrelapse<-MSrelapse[which(MSrelapse$STUDYID!="C-1802"),]
  return(MSrelapse)
}
htx-r/RiskModelNMApredictions documentation built on June 12, 2019, 9:52 a.m.