Closed bergsmat closed 4 years ago
To support PsN 4.8. With the old function, something goes wrong in printing ‘BACKWARDS STEP 1’ etc….
Need PsN 4.8 example files that break old version.
Update as of 28 Jan 2020: Tested the function on a messy output from SCM, and updates were needed. The latest version of function provided here:
nm.process.scm.new = function (path) {
myfile = paste(path, "scmlog.txt", sep="/")
scm = readLines(myfile)
updatetext = function(x) { x = gsub("TEST OFV (DROP)", " TestOFV ", x, fixed = TRUE) x = gsub("BASE OFV", " BaseOFV", x) x = gsub("NEW OFV", " NewOFV", x) x = gsub(">", " ", x) return(x) }
scm = updatetext(scm)
con <- file(myfile) writeLines(scm, con) close(con)
skip <- c("Model", "--------------------", "CRITERION", "BASE_MODEL_OFV", "CHOSEN_MODEL_OFV", "Relations", "--------------------", "MODEL")
%nin%
<- Negate(%in%
)
con <- file(myfile) open(con) scm <- read.table(con, fill=TRUE) %>% filter(V9!="" | V8!="" | V7!="") %>% filter(V1 %nin% skip) %>% mutate(Chosen = ifelse(grepl("-", V8), ifelse(grepl("e", V8), NA, V8), NA)) %>% mutate(V9 = paste(V8, V9, sep=" "), V8 = ifelse(grepl("YES!", V8), "YES", ""), row = as.numeric(rownames(.)), Step = ifelse(grepl("forward", V6), "Forward", ifelse(grepl("backward", V6), "Backward", ifelse(row==1, "Forward", ifelse(grepl("inside", V7), "Backward", NA)))), V3 = signif(as.numeric(V3)), V4=signif(as.numeric(V4)), V5 = signif(as.numeric(V5)), V6=signif(as.numeric(V6)), V1 = gsub("Parameter-covariate", "", V1, fixed = TRUE), V1 = gsub("Forward", "", V1), V7 = gsub("step:", "", V7, fixed = TRUE), V7 = gsub("inside", "", V7))%>% select(Step, V1, V3, V4, V5, V6, V7, V8, V9, Chosen) names(scm) <- c("Step", "Model", "OFV_base", "OFV_test", "dOFV", "Goal", "dDF", "Significant", "p-value", "Chosen") close(con)
scm <- scm %>% mutate(p-value
= gsub("[^0-9.-]", "", p-value
)) %>%
mutate(p-value
= readr::parse_number(p-value
)) %>%
mutate(dDF = as.numeric(dDF)) %>%
mutate(p-value
= ifelse(as.numeric(p-value
)>0.9999, ">0.9999",
ifelse(as.numeric(p-value
)<0.0001, "<0.0001",
as.character(signif(as.numeric(p-value
), 3)))))
return(scm) }
shortscm code:
nm.process.scm.short = function(path) {
scm = nm.process.scm.new(path)
forward = scm %>% filter(Step == "Forward") %>% mutate(Chosen = gsub("-", "", Chosen, fixed = TRUE)) forward = unique(forward$Chosen)
backward = scm %>% filter(Step == "Backward") %>% mutate(Chosen = gsub("-", "", Chosen, fixed = TRUE)) backward = unique(backward$Chosen)
%nin%
<- Negate(%in%
)
shortscm = scm %>% filter(Significant=="YES") %>% mutate(Model1 = gsub("-", "", Model, fixed = TRUE)) %>% filter(Model1 %in% forward) %>% filter(Model1 %nin% backward) %>% select(-Step, -Chosen, -Model1) %>% group_by(Model) %>% slice(1) %>% ungroup()
return(shortscm) }
fixed @2fa3b
per Marita: