Skip to content

Commit c1aac48

Browse files
authored
Merge pull request #182 from jdblischak/data-frame-cbind
Replace data.frame(cbind()) with data.frame()
2 parents daea8db + 79d537c commit c1aac48

File tree

7 files changed

+49
-48
lines changed

7 files changed

+49
-48
lines changed

R/gsBinomial.R

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,17 @@ nBinomial <- function(p1, p2, alpha = 0.025, beta = 0.1, delta0 = 0, ratio = 1,
176176
if (is.null(n)) {
177177
n <- ((z.alpha * sigma0 + z.beta * sigma1) / (p1 - p2 - delta0))^2
178178
if (outtype == 2) {
179-
return(data.frame(cbind(n1 = n / (ratio + 1), n2 = ratio *
180-
n / (ratio + 1))))
179+
return(data.frame(n1 = n / (ratio + 1), n2 = ratio *
180+
n / (ratio + 1)))
181181
}
182182
else if (outtype == 3) {
183-
return(data.frame(cbind(
183+
return(data.frame(
184184
n = n, n1 = n / (ratio + 1),
185185
n2 = ratio * n / (ratio + 1), alpha = alpha,
186186
sided = sided, beta = beta, Power = 1 - beta,
187187
sigma0 = sigma0, sigma1 = sigma1, p1 = p1,
188188
p2 = p2, delta0 = delta0, p10 = p10, p20 = p20
189-
)))
189+
))
190190
}
191191
else {
192192
return(n = n)
@@ -196,17 +196,17 @@ nBinomial <- function(p1, p2, alpha = 0.025, beta = 0.1, delta0 = 0, ratio = 1,
196196
pwr <- stats::pnorm(-(stats::qnorm(1 - alpha / sided) - sqrt(n) *
197197
((p1 - p2 - delta0) / sigma0)) * sigma0 / sigma1)
198198
if (outtype == 2) {
199-
return(data.frame(cbind(n1 = n / (ratio + 1), n2 = ratio *
200-
n / (ratio + 1), Power = pwr)))
199+
return(data.frame(n1 = n / (ratio + 1), n2 = ratio *
200+
n / (ratio + 1), Power = pwr))
201201
}
202202
else if (outtype == 3) {
203-
return(data.frame(cbind(
203+
return(data.frame(
204204
n = n, n1 = n / (ratio + 1),
205205
n2 = ratio * n / (ratio + 1), alpha = alpha,
206206
sided = sided, beta = 1 - pwr, Power = pwr,
207207
sigma0 = sigma0, sigma1 = sigma1, p1 = p1,
208208
p2 = p2, delta0 = delta0, p10 = p10, p20 = p20
209-
)))
209+
))
210210
}
211211
else {
212212
return(Power = pwr)
@@ -232,19 +232,19 @@ nBinomial <- function(p1, p2, alpha = 0.025, beta = 0.1, delta0 = 0, ratio = 1,
232232
if (is.null(n)) {
233233
n <- ((z.alpha * sigma0 + z.beta * sigma1) / (p1 - p2 * RR))^2
234234
if (outtype == 2) {
235-
return(data.frame(cbind(
235+
return(data.frame(
236236
n1 = n / (ratio + 1),
237237
n2 = ratio * n / (ratio + 1)
238-
)))
238+
))
239239
}
240240
else if (outtype == 3) {
241-
return(data.frame(cbind(
241+
return(data.frame(
242242
n = n, n1 = n / (ratio + 1),
243243
n2 = ratio * n / (ratio + 1), alpha = alpha,
244244
sided = sided, beta = beta, Power = 1 - beta,
245245
sigma0 = sigma0, sigma1 = sigma1, p1 = p1,
246246
p2 = p2, delta0 = delta0, p10 = p10, p20 = p20
247-
)))
247+
))
248248
}
249249
else {
250250
return(n = n)
@@ -254,17 +254,17 @@ nBinomial <- function(p1, p2, alpha = 0.025, beta = 0.1, delta0 = 0, ratio = 1,
254254
pwr <- stats::pnorm(-(stats::qnorm(1 - alpha / sided) - sqrt(n) *
255255
((p1 - p2 * RR) / sigma0)) * sigma0 / sigma1)
256256
if (outtype == 2) {
257-
return(data.frame(cbind(n1 = n / (ratio + 1), n2 = ratio *
258-
n / (ratio + 1), Power = pwr)))
257+
return(data.frame(n1 = n / (ratio + 1), n2 = ratio *
258+
n / (ratio + 1), Power = pwr))
259259
}
260260
else if (outtype == 3) {
261-
return(data.frame(cbind(
261+
return(data.frame(
262262
n = n, n1 = n / (ratio + 1),
263263
n2 = ratio * n / (ratio + 1), alpha = alpha,
264264
sided = sided, beta = 1 - pwr, Power = pwr,
265265
sigma0 = sigma0, sigma1 = sigma1, p1 = p1,
266266
p2 = p2, delta0 = delta0, p10 = p10, p20 = p20
267-
)))
267+
))
268268
}
269269
else {
270270
return(Power = pwr)
@@ -288,17 +288,17 @@ nBinomial <- function(p1, p2, alpha = 0.025, beta = 0.1, delta0 = 0, ratio = 1,
288288
if (is.null(n)) {
289289
n <- ((z.alpha * sigma0 + z.beta * sigma1) / log(OR / p2 * (1 - p2) * p1 / (1 - p1)))^2
290290
if (outtype == 2) {
291-
return(data.frame(cbind(n1 = n / (ratio + 1), n2 = ratio *
292-
n / (ratio + 1))))
291+
return(data.frame(n1 = n / (ratio + 1), n2 = ratio *
292+
n / (ratio + 1)))
293293
}
294294
else if (outtype == 3) {
295-
return(data.frame(cbind(
295+
return(data.frame(
296296
n = n, n1 = n / (ratio + 1),
297297
n2 = ratio * n / (ratio + 1), alpha = alpha,
298298
sided = sided, beta = beta, Power = 1 - beta,
299299
sigma0 = sigma0, sigma1 = sigma1, p1 = p1,
300300
p2 = p2, delta0 = delta0, p10 = p10, p20 = p20
301-
)))
301+
))
302302
}
303303
else {
304304
return(n = n)
@@ -309,17 +309,17 @@ nBinomial <- function(p1, p2, alpha = 0.025, beta = 0.1, delta0 = 0, ratio = 1,
309309
(log(OR / p2 * (1 - p2) * p1 / (1 - p1)) / sigma0)) *
310310
sigma0 / sigma1)
311311
if (outtype == 2) {
312-
return(data.frame(cbind(n1 = n / (ratio + 1), n2 = ratio *
313-
n / (ratio + 1), Power = pwr)))
312+
return(data.frame(n1 = n / (ratio + 1), n2 = ratio *
313+
n / (ratio + 1), Power = pwr))
314314
}
315315
else if (outtype == 3) {
316-
return(data.frame(cbind(
316+
return(data.frame(
317317
n = n, n1 = n / (ratio + 1),
318318
n2 = ratio * n / (ratio + 1), alpha = alpha,
319319
sided = sided, beta = 1 - pwr, Power = pwr,
320320
sigma0 = sigma0, sigma1 = sigma1, p1 = p1,
321321
p2 = p2, delta0 = delta0, p10 = p10, p20 = p20
322-
)))
322+
))
323323
}
324324
else {
325325
return(Power = pwr)

R/gsMethods.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ gsBoundSummary0 <- function(
357357
if (x$test.type > 1) {
358358
pframe2 <- NULL
359359
for (i in 1:length(x$theta)) pframe2 <- rbind(pframe2, data.frame("Futility" = cumsum(x$lower$prob[, i])))
360-
pframe <- data.frame(cbind("Value" = pframe[, 1], pframe2, pframe[, -1]))
360+
pframe <- data.frame("Value" = pframe[, 1], pframe2, pframe[, -1])
361361
}
362362
# conditional power at bound, theta=hat(theta)
363363
cp <- data.frame(gsBoundCP(x, r = r))
@@ -384,17 +384,18 @@ gsBoundSummary0 <- function(
384384
} else {
385385
Futility <- NULL
386386
}
387+
# cbind() required here to drop Futility column when it is NULL
387388
pp <- data.frame(cbind(Efficacy, Futility, i = 1:(x$k - 1)))
388389
pp$Value <- "PP"
389390
}
390391
# start a frame for other statistics
391392
# z at bounds
392393
statframe <- data.frame("Value" = "Z", "Efficacy" = x$upper$bound, i = 1:x$k)
393-
if (x$test.type > 1) statframe <- data.frame(cbind(statframe, "Futility" = x$lower$bound))
394+
if (x$test.type > 1) statframe <- data.frame(statframe, "Futility" = x$lower$bound)
394395
# add nominal p-values at each bound
395396
tem <- data.frame("Value" = "p (1-sided)", "Efficacy" = stats::pnorm(x$upper$bound, lower.tail = FALSE), i = 1:x$k)
396-
if (x$test.type == 2) tem <- data.frame(cbind(tem, "Futility" = stats::pnorm(x$lower$bound, lower.tail = TRUE)))
397-
if (x$test.type > 2) tem <- data.frame(cbind(tem, "Futility" = stats::pnorm(x$lower$bound, lower.tail = FALSE)))
397+
if (x$test.type == 2) tem <- data.frame(tem, "Futility" = stats::pnorm(x$lower$bound, lower.tail = TRUE))
398+
if (x$test.type > 2) tem <- data.frame(tem, "Futility" = stats::pnorm(x$lower$bound, lower.tail = FALSE))
398399
statframe <- rbind(statframe, tem)
399400
# delta values at bounds
400401
tem <- data.frame("Value" = paste("~", deltaname, " at bound", sep = ""), "Efficacy" = deltaefficacy, i = 1:x$k)

R/gsSurv.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,10 +1383,10 @@ xtable.gsSurv <- function(x, caption = NULL, label = NULL, align = NULL, digits
13831383
paste(eff[neff], "\\\\ \\hline \\multicolumn{4}{p{", fnwid, "}}{\\footnotesize", footnote, "}")
13841384
}
13851385
if (x$test.type != 1) {
1386-
xxtab <- data.frame(cbind(an, stat, fut, eff))
1386+
xxtab <- data.frame(an, stat, fut, eff)
13871387
colnames(xxtab) <- c("Analysis", "Value", "Futility", "Efficacy")
13881388
} else {
1389-
xxtab <- data.frame(cbind(an, stat, eff))
1389+
xxtab <- data.frame(an, stat, eff)
13901390
colnames(xxtab) <- c("Analysis", "Value", "Efficacy")
13911391
}
13921392
return(xtable::xtable(xxtab,

R/nEvents.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ nEvents <- function(hr = .6, alpha = .025, beta = .1, ratio = 1, sided = 1, hr0
99
if (n[1] == 0) {
1010
n <- (stats::qnorm(1 - alpha / sided) + stats::qnorm(1 - beta))^2 / delta^2
1111
if (tbl) {
12-
n <- data.frame(cbind(
12+
n <- data.frame(
1313
hr = hr, n = ceiling(n), alpha = alpha,
1414
sided = sided, beta = beta,
1515
Power = 1 - beta, delta = delta, ratio = ratio,
1616
hr0 = hr0, se = 1 / c / sqrt(ceiling(n))
17-
))
17+
)
1818
}
1919
return(n)
2020
}
2121
else {
2222
pwr <- stats::pnorm(-(stats::qnorm(1 - alpha / sided) - sqrt(n) * delta))
2323
if (tbl) {
24-
pwr <- data.frame(cbind(
24+
pwr <- data.frame(
2525
hr = hr, n = n, alpha = alpha,
2626
sided = sided, beta = 1 - pwr,
2727
Power = pwr, delta = delta, ratio = ratio,
2828
hr0 = hr0, se = sqrt(1 / n) / c
29-
))
29+
)
3030
}
3131
return(pwr)
3232
}

R/nNormal.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,28 +110,28 @@ nNormal <- function(delta1 = 1, sd = 1.7, sd2 = NULL, alpha = .025,
110110
if (is.null(n)) {
111111
n <- ((stats::qnorm(alpha / sided) + stats::qnorm(beta)) / theta1)^2
112112
if (outtype == 2) {
113-
return(data.frame(cbind(n1 = n / (ratio + 1), n2 = ratio * n / (ratio + 1))))
113+
return(data.frame(n1 = n / (ratio + 1), n2 = ratio * n / (ratio + 1)))
114114
}
115115
else if (outtype == 3) {
116-
return(data.frame(cbind(
116+
return(data.frame(
117117
n = n, n1 = n / (ratio + 1), n2 = ratio * n / (ratio + 1),
118118
alpha = alpha, sided = sided, beta = beta, Power = 1 - beta,
119119
sd = sd, sd2 = sd2, delta1 = delta1, delta0 = delta0, se = se / sqrt(n)
120-
)))
120+
))
121121
}
122122
else {
123123
return(n = n)
124124
}
125125
} else {
126126
powr <- stats::pnorm(sqrt(n) * theta1 - stats::qnorm(1 - alpha / sided))
127127
if (outtype == 2) {
128-
return(data.frame(cbind(n1 = n / (ratio + 1), n2 = ratio * n / (ratio + 1), Power = powr)))
128+
return(data.frame(n1 = n / (ratio + 1), n2 = ratio * n / (ratio + 1), Power = powr))
129129
} else if (outtype == 3) {
130-
return(data.frame(cbind(
130+
return(data.frame(
131131
n = n, n1 = n / (ratio + 1), n2 = ratio * n / (ratio + 1),
132132
alpha = alpha, sided = sided, beta = 1 - powr, Power = powr,
133133
sd = sd, sd2 = sd2, delta1 = delta1, delta0 = delta0, se = se / sqrt(n)
134-
)))
134+
))
135135
}
136136
else {
137137
(return(Power = powr))

R/ssrCP.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ n2sizediff <- function(z1, target, beta = .1, z2 = z2NC,
268268
#' )
269269
#' # combine data frames from these designs
270270
#' y <- rbind(
271-
#' data.frame(cbind(xx$dat, Test = "Normal combination")),
272-
#' data.frame(cbind(xxZ$dat, Test = "Sufficient statistic")),
273-
#' data.frame(cbind(xxFisher$dat, Test = "Fisher combination"))
271+
#' data.frame(xx$dat, Test = "Normal combination"),
272+
#' data.frame(xxZ$dat, Test = "Sufficient statistic"),
273+
#' data.frame(xxFisher$dat, Test = "Fisher combination")
274274
#' )
275275
#' # plot stage 2 statistic required for positive combination test
276276
#' ggplot2::ggplot(data = y, ggplot2::aes(x = z1, y = z2, col = Test)) +
@@ -288,8 +288,8 @@ n2sizediff <- function(z1, target, beta = .1, z2 = z2NC,
288288
#' )
289289
#' # combine data frames for the 2 designs
290290
#' y <- rbind(
291-
#' data.frame(cbind(xx$dat, "CP effect size" = "Obs. at IA")),
292-
#' data.frame(cbind(xxtheta1$dat, "CP effect size" = "Alt. hypothesis"))
291+
#' data.frame(xx$dat, "CP effect size" = "Obs. at IA"),
292+
#' data.frame(xxtheta1$dat, "CP effect size" = "Alt. hypothesis")
293293
#' )
294294
#' # plot stage 2 sample size by design
295295
#' ggplot2::ggplot(data = y, ggplot2::aes(x = z1, y = n2, col = CP.effect.size)) +
@@ -299,8 +299,8 @@ n2sizediff <- function(z1, target, beta = .1, z2 = z2NC,
299299
#' y2 <- Power.ssrCP(x = xxtheta1)
300300
#' # combine data frames for the 2 designs
301301
#' y3 <- rbind(
302-
#' data.frame(cbind(y1, "CP effect size" = "Obs. at IA")),
303-
#' data.frame(cbind(y2, "CP effect size" = "Alt. hypothesis"))
302+
#' data.frame(y1, "CP effect size" = "Obs. at IA"),
303+
#' data.frame(y2, "CP effect size" = "Alt. hypothesis")
304304
#' )
305305
#' # plot expected sample size by design and effect size
306306
#' ggplot2::ggplot(data = y3, ggplot2::aes(x = delta, y = en, col = CP.effect.size)) +

R/xtable.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ xtable.gsDesign <- function(x, caption = NULL, label = NULL, align = NULL, digit
9999
fnwid, "}}{\\footnotesize", footnote, "}"
100100
)
101101
}
102-
x <- data.frame(cbind(an, stat, fut, eff))
102+
x <- data.frame(an, stat, fut, eff)
103103
colnames(x) <- c("Analysis", "Value", "Futility", "Efficacy")
104104
xtable::xtable(x, caption = caption, label = label, align = align, digits = digits, display = display, ...)
105105
}

0 commit comments

Comments
 (0)