-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Baptiste Nusaibah validation #11
base: main
Are you sure you want to change the base?
Changes from 4 commits
63521d9
15f314a
b3c2fb8
2af87f8
6a4b9e7
c39b6fd
7d743c5
e5d6c1a
99e08ff
dcb1467
e5447f8
d8c1d68
cc6e7fa
60b5318
e272d83
3d6074c
09a1057
632809c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Package: grstat | ||
Type: Package | ||
Title: Clinical Research Tools | ||
Version: 0.1.0.9004 | ||
Version: 0.1.0.9006 | ||
Authors@R: c( | ||
person("Dan", "Chaltiel", role = c("aut", "cre"), | ||
email = "[email protected]", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
compair_grade <- function(tabR,tabSAS){ | ||
DanChaltiel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (nrow(tabR)!=nrow(tabSAS)){stop("Different number of grade levels") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. soit sur une ligne, sans les {}, |
||
|
||
if (ncol(tabR)!=ncol(tabSAS)){stop("Different number of arm")} | ||
if (all(dim(tabR)==dim(tabSAS))){ | ||
print("Check: same dimension of tables") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. programmation défensive: on ne print pas si tout va bien, on warn s'il y a un problème |
||
df=tabR%>%arrange(grade)%>%full_join(tabSAS,by="grade",suffix = c(".r",".sas")) | ||
indice=which(df[,paste0(tabR%>%select(-grade)%>%colnames(),paste=".r")]!=df[,paste0(tabSAS%>%select(-grade)%>%colnames(),paste=".sas")], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. je n'aime vraiment pas les indices, je trouve que c'est à risque d'erreur |
||
arr.ind=TRUE) | ||
indice[,"col"]=indice[,"col"]+1 # parce qu'on avait retiré le grade | ||
} | ||
if (nrow(indice)!=0){ | ||
print(indice) | ||
warning(paste0("Comparison result: Warning! Different outputs.\n", | ||
nrow(indice)," mismatching between the two tables. Above, the indices.")) | ||
|
||
}else{ | ||
warning("Comparison result: same outputs") | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#fonction grouping figures of missing grades and grades 0 for R function ae_table_grade | ||
group_grades_zeroNA <- function(data, round = 0){ | ||
|
||
#suming N of missing grades and grades 0 | ||
data <- data %>% | ||
mutate(grade = replace_na(grade, 0)) %>% | ||
group_by(grade) %>% | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
mutate(across(starts_with("N"), ~sum(., na.rm = T))) %>% | ||
distinct(grade, .keep_all = T) %>% | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On ne peut pas remplacer mutate+distinct par summarise ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. je crois que c'est parce que je n'arrivais pas à keep toutes les variables dans la base avec summarize(.by=) quand il y avait plusieurs bras |
||
ungroup() | ||
|
||
#recalculating pct | ||
ngroups <- (ncol(data) - 1) / 2 | ||
for(i in 1:ngroups){ | ||
npatients <- sum(data[, paste0("N", i)]) | ||
data[data$grade == 0, paste0("pct", i)] <- round(data[data$grade == 0, paste0("N", i)] * 100 / npatients, round) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je vais avoir besoin de lancer le code pour trouver comment appliquer purrr |
||
|
||
data <- data %>% arrange(grade) | ||
|
||
return(data) | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#fonction separating each column N(pct) into 2 columns N and pct | ||
separate_n_pct <- function(data){ | ||
|
||
#separation of 1 character column into 2 character columns | ||
data <- colnames(data) %>% | ||
imap( | ||
~data %>% select(all_of(.x)) %>% | ||
separate(.x, into = c(paste0("N", .y), paste0("pct", .y)), sep = "\\(") | ||
) %>% | ||
bind_cols() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://tidyr.tidyverse.org/reference/separate_wider_delim.html |
||
|
||
#extraction of figures into numeric columns | ||
data <- data %>% | ||
mutate( | ||
across(everything(), ~as.numeric(str_extract(.x, "\\d+\\.?\\d*"))) | ||
) | ||
|
||
return(data) | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#fonction comparing R and SAS outputs | ||
validate_ae_table_grade <- function(R_output, | ||
SAS_output, | ||
round = 0 #rounding of recalculated percentages in group_grades_zeroNA() | ||
){ | ||
|
||
#formatting grade from character to numeric | ||
R_output <- R_output %>% | ||
mutate(grade = ifelse(variable == "No declared AE", 0, as.numeric(str_extract(variable, "\\d")))) | ||
SAS_output <- SAS_output %>% | ||
mutate(grade = as.numeric(str_extract(max_aegr1, "\\d"))) | ||
|
||
#separating each column N(pct) into 2 columns N and pct | ||
R_separated <- R_output %>% select(grade) %>% | ||
bind_cols( | ||
separate_n_pct(R_output %>% select(-c(.id, label, variable, grade))) | ||
) | ||
SAS_separated <- SAS_output %>% select(grade) %>% | ||
bind_cols( | ||
separate_n_pct(SAS_output %>% select(-c(max_aegr1, grade))) | ||
) | ||
|
||
#missing figure with macro SAS <=> 0 with R package | ||
SAS_separated <- SAS_separated %>% | ||
replace(is.na(.), 0) | ||
|
||
#grouping figures of missing grades and grades 0 for R function | ||
R_separated <- group_grades_zeroNA(R_separated, round = round) | ||
|
||
return(list(R = R_separated, SAS = SAS_separated)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ce seront des fonctions de testing, elles ne doivent pas aller dans R/
Utilise
usethis::use_test_helper()
Tu peux aussi aller voir la doc de testthat: https://cran.r-project.org/web/packages/testthat/vignettes/special-files.html