Explorar o código

Prettyfying cox

Andrej hai 2 semanas
pai
achega
fb7ee18cb0
Modificáronse 1 ficheiros con 10 adicións e 9 borrados
  1. 10 9
      R/cox.R

+ 10 - 9
R/cox.R

@@ -28,30 +28,30 @@ cox.univariate<-function(x,var){
    qv=base::strsplit(data,split=':')[[1]]
    mode=qv[1]
    v=qv[2]
-   #print(sprintf('Calculating for %s',var))
    s=cox.hazard(x,v)
    s1<-base::summary(s)  
   
-   #calculate survival probability at mean or prescribed value, which is given as false for binary and as predifined value with categorical data
+#calculate hazard ratio per std(m), given unit (u) or unit change (
+
+#take std
    if (mode=='m'){
-      #use sd as a unit change
       x.dx<-stats::sd(x[,v],na.rm=TRUE)
    }
+
+#use whatever follows u
    if (base::substr(mode,1,1)=='u'){
-       #use specified unit
       x.dx=base::as.numeric(base::substring(mode,2))
    }
    
+#take unit change
    if (mode=='logic'){
-       #unit is 1 
       x.dx=1
-       
    }
    if (substr(mode,1,1)=='r'){
-       #the same as for logic
       x.dx=1
    }
-   	#adjust output data
+
+#adjust output data
    sd=base::sqrt(s$var)*x.dx
    c=s1$coef[1]*x.dx
    l95=base::round(base::exp(c-1.96*sd),2)
@@ -61,7 +61,8 @@ cox.univariate<-function(x,var){
    pLikelihood=base::round(s1$logtest['pvalue'],3)
    unitChange=base::round(x.dx,2)
 #return as data frame with a single row
-   base::data.frame(varName=v,unitChange=unitChange,HR=HR,low95=l95,up95=u95,pWald=pWald,pLikelihood=pLikelihood)
+   base::data.frame(varName=v,unitChange=unitChange,
+      HR=HR,low95=l95,up95=u95,pWald=pWald,pLikelihood=pLikelihood)
   
 }