Skip to content

Commit 1815151

Browse files
authored
update to fix error with multicore on windows
1 parent d9cce76 commit 1815151

1 file changed

Lines changed: 111 additions & 4 deletions

File tree

R/curve_gen.R

Lines changed: 111 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#' logistic regression and the 'glm' function. Similarly, the Glm function from the
2525
#' rms package can also be used for this option. The gls method allows objects from gls()
2626
#' or from Gls() from the rms package.
27-
#' @param log Determines whether the coefficients will be exponentiated or not. By default,
27+
#' @param log Determines whether the coefficients will be exponentiated or not. By default,
2828
#' it is off and set to FALSE or F, but changing this to TRUE or T, will exponentiate the results
2929
#' which may be useful if trying to view the results from a logistic regression on a scale that is not
3030
#' logarithmic.
@@ -59,6 +59,111 @@
5959
#' bob <- curve_gen(rob, "GroupB")
6060
#' }
6161
#'
62+
#'
63+
64+
if ((Sys.info()["sysname"]) == "Windows") {
65+
66+
67+
curve_gen <- function(model, var, method = "lm", log = FALSE, penalty = NULL, m = NULL,
68+
steps = 1000, table = TRUE) {
69+
if (is.character(method) != TRUE) {
70+
stop("Error: 'method' must be a character vector")
71+
}
72+
if (is.numeric(steps) != TRUE) {
73+
stop("Error: 'steps' must be a numeric vector")
74+
}
75+
76+
intrvls <- (1:(steps - 1)) / steps
77+
78+
# No adjustment for multiple comparisons ----------------------------------
79+
80+
if (is.null(penalty) & is.null(m)) {
81+
if (method == "lm") {
82+
results <- lapply(intrvls, FUN = function(i) confint.default(object = model, level = i)[var, ])
83+
} else if (method == "rlm") {
84+
results <- lapply(intrvls, FUN = function(i) confint(object = model, level = i)[var, ])
85+
} else if (method == "glm") {
86+
results <- lapply(intrvls, FUN = function(i) confint(object = model, level = i, trace = FALSE)[var, ])
87+
} else if (method == "aov") {
88+
results <- lapply(intrvls, FUN = function(i) confint(object = model, level = i)[var, ])
89+
} else if (method == "gls") {
90+
results <- lapply(intrvls, FUN = function(i) confint.default(object = model, level = i)[var, ])
91+
}
92+
93+
# Bonferroni adjustment for multiple comparisons --------------------------
94+
} else if (penalty == "bonferroni" & m > 1) {
95+
bon.adj <- (1 - ((1 - intrvls) / m))
96+
97+
if (method == "lm") {
98+
results <- lapply(bon.adj, FUN = function(i) confint.default(object = model, level = i)[var, ])
99+
} else if (method == "rlm") {
100+
results <- lapply(bon.adj, FUN = function(i) confint(object = model, level = i)[var, ])
101+
} else if (method == "glm") {
102+
results <- lapply(bon.adj, FUN = function(i) confint(object = model, level = i, trace = FALSE)[var, ])
103+
} else if (method == "aov") {
104+
results <- lapply(bon.adj, FUN = function(i) confint(object = model, level = i)[var, ])
105+
} else if (method == "gls") {
106+
results <- lapply(bon.adj, FUN = function(i) confint.default(object = model, level = i)[var, ])
107+
}
108+
109+
# Sidak adjustment for multiple comparisons -------------------------------
110+
} else if (penalty == "sidak" & m > 1) {
111+
sidak.adj <- (((intrvls)^(1 / m)))
112+
113+
if (method == "lm") {
114+
results <- lapply(sidak.adj, FUN = function(i) confint.default(object = model, level = i)[var, ])
115+
} else if (method == "rlm") {
116+
results <- lapply(sidak.adj, FUN = function(i) confint(object = model, level = i)[var, ])
117+
} else if (method == "glm") {
118+
results <- lapply(sidak.adj, FUN = function(i) confint(object = model, level = i, trace = FALSE)[var, ])
119+
} else if (method == "aov") {
120+
results <- lapply(sidak.adj, FUN = function(i) confint(object = model, level = i)[var, ])
121+
} else if (method == "gls") {
122+
results <- lapply(sidak.adj, FUN = function(i) confint.default(object = model, level = i)[var, ])
123+
}
124+
}
125+
126+
127+
128+
df <- data.frame(do.call(rbind, results))
129+
130+
if (log == FALSE) {
131+
df <- (df)
132+
} else if (log == TRUE) {
133+
df <- exp(df)
134+
}
135+
136+
intrvl.limit <- c("lower.limit", "upper.limit")
137+
colnames(df) <- intrvl.limit
138+
df$intrvl.width <- (abs((df$upper.limit) - (df$lower.limit)))
139+
df$intrvl.level <- intrvls
140+
df$cdf <- (abs(df$intrvl.level / 2)) + 0.5
141+
df$pvalue <- 1 - intrvls
142+
df$svalue <- -log2(df$pvalue)
143+
df <- head(df, -1)
144+
class(df) <- c("data.frame", "concurve")
145+
densdf <- data.frame(c(df$lower.limit, df$upper.limit))
146+
colnames(densdf) <- "x"
147+
densdf <- head(densdf, -1)
148+
class(densdf) <- c("data.frame", "concurve")
149+
150+
151+
if (table == TRUE) {
152+
levels <- c(0.25, 0.50, 0.75, 0.80, 0.85, 0.90, 0.95, 0.975, 0.99)
153+
(df_subintervals <- (curve_table(df, levels, type = "c", format = "data.frame")))
154+
class(df_subintervals) <- c("data.frame", "concurve")
155+
dataframes <- list(df, densdf, df_subintervals)
156+
names(dataframes) <- c("Intervals Dataframe", "Intervals Density", "Intervals Table")
157+
class(dataframes) <- "concurve"
158+
return(dataframes)
159+
} else if (table == FALSE) {
160+
return(list(df, densdf))
161+
}
162+
}
163+
164+
} else if ((Sys.info()["sysname"]) == "Darwin") {
165+
166+
62167
curve_gen <- function(model, var, method = "lm", log = FALSE, penalty = NULL, m = NULL,
63168
steps = 1000, cores = getOption("mc.cores", 1L), table = TRUE) {
64169
if (is.character(method) != TRUE) {
@@ -117,17 +222,17 @@ curve_gen <- function(model, var, method = "lm", log = FALSE, penalty = NULL, m
117222
results <- pbmclapply(sidak.adj, FUN = function(i) confint.default(object = model, level = i)[var, ], mc.cores = cores)
118223
}
119224
}
120-
225+
121226

122227

123228
df <- data.frame(do.call(rbind, results))
124-
229+
125230
if (log == FALSE) {
126231
df <- (df)
127232
} else if (log == TRUE) {
128233
df <- exp(df)
129234
}
130-
235+
131236
intrvl.limit <- c("lower.limit", "upper.limit")
132237
colnames(df) <- intrvl.limit
133238
df$intrvl.width <- (abs((df$upper.limit) - (df$lower.limit)))
@@ -156,5 +261,7 @@ curve_gen <- function(model, var, method = "lm", log = FALSE, penalty = NULL, m
156261
}
157262
}
158263

264+
}
265+
159266
# RMD Check
160267
utils::globalVariables(c("df", "lower.limit", "upper.limit", "intrvl.width", "intrvl.level", "cdf", "pvalue", "svalue"))

0 commit comments

Comments
 (0)