Browse Source

fix incidence table

fix-cran1
François Vieille 1 year ago
parent
commit
eb3ee16751
2 changed files with 24 additions and 18 deletions
  1. 14
    8
      R/tools.R
  2. 10
    10
      R/tree.R

+ 14
- 8
R/tools.R View File

@@ -41,7 +41,7 @@ vt.subgroups <- function(vt.trees, only.leaf = T, only.fav = T, tables = F, verb
41 41
     unique(do.call(rbind, subgroups))
42 42
   }
43 43
   else{
44
-    subgroups <- vt.tree$getRules(only.leaf = only.leaf, only.fav = only.fav, tables = tables, verbose = verbose, compete = compete)
44
+    subgroups <- vt.trees$getRules(only.leaf = only.leaf, only.fav = only.fav, tables = tables, verbose = verbose, compete = compete)
45 45
   }
46 46
 }
47 47
 
@@ -60,21 +60,27 @@ vt.getQAOriginal <- function(response, trt, ahat){
60 60
 }
61 61
 
62 62
 vt.getTable <- function(table){
63
-  if(is.list(table)) table <-  table[[1]]
64
-  Incidence <- function(X) as.character(round(X[2] / X[3], digits = 3))
63
+  if(is.list(table)) table <- table[[1]]
64
+  Incidence <- function(X) round(X[2] / X[3], digits = 3)
65 65
   t <- stats::addmargins(table, margin = c(1,2), FUN = sum, quiet = T)
66 66
   t <- stats::addmargins(t, FUN = Incidence, margin = 1, quiet = T)
67
-  rr <- as.numeric(t["Incidence", "1"]) / as.numeric(t["Incidence", "0"])
67
+  rr <- NA_real_
68
+  if(nrow(t) == 4) rr <- t[4, 2] / t[4, 1]
68 69
   return(list(table = t, rr = rr))
69 70
 }
70 71
 
71 72
 vt.getIncidence <- function(df){
72 73
   if (nrow(df) == 0) table.res <- NULL
74
+  if (ncol(df) != 2) table.res <- NULL
73 75
   else{
74
-    table.res <- vt.getTable(table(df[, 1],
75
-                                   df[, 2],
76
-                                   deparse.level = 2,
77
-                                   dnn = c("resp", "trt")))
76
+    table.res <- vt.getTable(
77
+      table(
78
+        factor(df[, 1], levels = c(0, 1)),
79
+        factor(df[, 2], levels = c(0, 1)),
80
+        deparse.level = 2,
81
+        dnn = c("resp", "trt")
82
+      )
83
+    )
78 84
   }
79 85
   return(table.res)
80 86
 }

+ 10
- 10
R/tree.R View File

@@ -248,17 +248,17 @@ VT.tree <- setRefClass(
248 248
           
249 249
           if(isTRUE(tables)){
250 250
             cat("\n")
251
-            cat(sprintf("Incidence dans la selection \n"))
251
+            cat(sprintf("Incidence in selection \n"))
252 252
             print(incid$table.selected$table)
253 253
             cat("\n")
254
-            cat(sprintf("Risque relatif (resub) : %0.3f \n", incid$table.selected$rr))
255
-            cat(sprintf("Risque relatif (snd) : %0.3f \n\n", incid$table.selected$rr.snd))
254
+            cat(sprintf("Relative risk (resub) : %0.3f \n", incid$table.selected$rr))
255
+            cat(sprintf("Relative risk (snd) : %0.3f \n\n", incid$table.selected$rr.snd))
256 256
             
257
-            cat(sprintf("Incidence dans le complementaire\n"))
257
+            cat(sprintf("Incidence in complement\n"))
258 258
             print(incid$table.not.selected$table)
259 259
             cat("\n")
260
-            cat(sprintf("Risque relatif (resub) : %0.3f \n", incid$table.not.selected$rr))
261
-            cat(sprintf("Risque relatif (snd) : %0.3f \n\n", incid$table.not.selected$rr.snd))
260
+            cat(sprintf("Relative risk (resub) : %0.3f \n", incid$table.not.selected$rr))
261
+            cat(sprintf("Relative risk (snd) : %0.3f \n\n", incid$table.not.selected$rr.snd))
262 262
           }
263 263
           
264 264
           cat("\n\n")
@@ -310,15 +310,15 @@ VT.tree <- setRefClass(
310 310
         table.A <- table.inc$table.selected
311 311
         table.A.cmpl <- table.inc$table.not.selected
312 312
         
313
-        cat(sprintf("Incidence dans le sous groupe A\n"))
313
+        cat(sprintf("Incidence in subgroup A\n"))
314 314
         print(table.A$table)
315 315
         cat("\n")
316
-        cat(sprintf("Risque relatif : %0.3f \n\n", table.A$risque_relatif))
316
+        cat(sprintf("Relative risk : %0.3f \n\n", table.A$risque_relatif))
317 317
         
318
-        cat(sprintf("Incidence dans le sous groupe A complementaire\n"))
318
+        cat(sprintf("Incidence in complement subgroup of A\n"))
319 319
         print(table.A.cmpl$table)
320 320
         cat("\n")
321
-        cat(sprintf("Risque relatif : %0.3f \n\n", table.A.cmpl$risque_relatif))
321
+        cat(sprintf("Relative risk : %0.3f \n\n", table.A.cmpl$risque_relatif))
322 322
       }else{
323 323
         return("Empty set")
324 324
       }

Loading…
Cancel
Save