Skip to content

Commit 25ccea3

Browse files
skpr v1.9.2: Fix correlation plot in skprGUI() not appearing right away
-Update FDS plot in skprGUI() to look better and add max PD -Fix plot_correlations()
1 parent 033d78d commit 25ccea3

File tree

6 files changed

+143
-42
lines changed

6 files changed

+143
-42
lines changed

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: skpr
22
Title: Design of Experiments Suite: Generate and Evaluate Optimal Designs
3-
Date: 2025-09-19
4-
Version: 1.9.1
3+
Date: 2025-09-26
4+
Version: 1.9.2
55
Authors@R: c(person("Tyler", "Morgan-Wall", email = "tylermw@gmail.com", role = c("aut", "cre")),
66
person("George", "Khoury", email = "george.m.khoury@gmail.com", role = c("aut")))
77
Description: Generates and evaluates D, I, A, Alias, E, T, and G optimal designs. Supports generation and evaluation of blocked and split/split-split/.../N-split plot designs. Includes parametric and Monte Carlo power evaluation functions, and supports calculating power for censored responses. Provides a framework to evaluate power using functions provided in other packages or written by the user. Includes a Shiny graphical user interface that displays the underlying code used to create and evaluate the design to improve ease-of-use and make analyses more reproducible. For details, see Morgan-Wall et al. (2021) <doi:10.18637/jss.v099.i01>.
@@ -10,7 +10,7 @@ Depends:
1010
R (>= 4.1.0)
1111
License: GPL-3
1212
Roxygen: list(markdown = TRUE)
13-
RoxygenNote: 7.3.2
13+
RoxygenNote: 7.3.3
1414
Imports:
1515
utils,
1616
iterators,

R/plot_correlations.R

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -115,33 +115,25 @@ plot_correlations = function(
115115
} else {
116116
model1 = model
117117
}
118-
119-
factornames = colnames(design)[
120-
unlist(lapply(design, class)) %in% c("factor", "character")
121-
]
122-
if (length(factornames) > 0) {
123-
contrastlist = list()
124-
for (name in 1:length(factornames)) {
125-
contrastlist[[factornames[name]]] = contr.simplex
126-
}
127-
} else {
128-
contrastlist = NULL
129-
}
118+
presetcontrasts = list()
119+
contrast_info = generate_contrast_list(
120+
design,
121+
presetcontrasts,
122+
contr.simplex
123+
)
124+
contrastslist_cormat = contrast_info$contrastslist_cormat
130125
#------Normalize/Center numeric columns ------#
131126
if (standardize) {
132-
for (column in seq_len(ncol(skpr_output))) {
133-
if (is.numeric(design[, column])) {
134-
midvalue = mean(c(max(design[, column]), min(design[, column])))
135-
design[, column] = (design[, column] - midvalue) /
136-
(max(design[, column]) - midvalue)
137-
}
138-
}
127+
design = normalize_design(design)
139128
}
129+
#Main effects model
130+
mm_main = model.matrix(~., design, contrasts.arg = contrastslist_cormat)
131+
#All interactions included
132+
mm = model.matrix(model1, design, contrasts.arg = contrastslist_cormat)
140133

141-
mm_main = model.matrix(model, design, contrasts.arg = contrastlist)
142-
mm = model.matrix(model1, design, contrasts.arg = contrastlist)
143134
X = mm_main[, -1, drop = FALSE]
144-
int_nms = setdiff(colnames(mm_main), colnames(mm)) # just the interactions
135+
int_nms = setdiff(colnames(mm), colnames(mm_main)) # just the interactions
136+
145137
Z = mm[, int_nms, drop = FALSE]
146138
W = solve(V)
147139

@@ -159,9 +151,10 @@ plot_correlations = function(
159151
imagecolors = colorRampPalette(customcolors)(101)
160152
}
161153
if (!is.null(custompar)) {
162-
warning("`custompar` is no longer supported; adjust the returned ggplot object instead.")
154+
warning(
155+
"`custompar` is no longer supported; adjust the returned ggplot object instead."
156+
)
163157
}
164-
165158
labels = colnames(mm)[-1]
166159
plot_matrix = t(cormat[ncol(cormat):1, , drop = FALSE])
167160
plot_df = data.frame(

R/plot_fds.R

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ plot_fds = function(
8989
values = fds_values[[i]]
9090
midval = values[mid_index(values)]
9191
fraction = seq_along(values) / length(values)
92+
maxval = max(values)
9293
df = data.frame(
9394
fraction = fraction,
9495
variance = values
@@ -108,19 +109,49 @@ plot_fds = function(
108109
linetype = "dashed",
109110
color = "red"
110111
) +
112+
ggplot2::geom_hline(
113+
yintercept = maxval,
114+
linetype = "dashed",
115+
color = "black"
116+
) +
117+
ggplot2::annotate(
118+
"text",
119+
label = sprintf("Mid PV: %0.3f", midval),
120+
x = 0,
121+
hjust = 0.0,
122+
y = midval,
123+
vjust = -0.25,
124+
fontface = "bold",
125+
size = 6,
126+
color = "red"
127+
) +
128+
ggplot2::annotate(
129+
"text",
130+
label = sprintf("Max PV: %0.3f", maxval),
131+
x = 0,
132+
hjust = 0.0,
133+
y = maxval,
134+
vjust = -0.25,
135+
size = 6,
136+
color = "black",
137+
fontface = "bold",
138+
) +
111139
ggplot2::scale_x_continuous(
112140
limits = c(0, 1),
113-
expand = ggplot2::expansion(mult = 0)
141+
expand = c(0, 0.0)
114142
) +
115143
ggplot2::scale_y_continuous(
116-
limits = c(0, yaxis_max),
144+
limits = c(0, maxyaxis),
117145
expand = ggplot2::expansion(mult = 0)
118146
) +
119147
ggplot2::labs(
120-
x = description[i],
148+
x = description,
121149
y = "Prediction Variance"
122150
) +
123-
ggplot2::theme_minimal()
151+
ggplot2::theme_minimal() +
152+
ggplot2::theme(margins = ggplot2::unit(c(20, 20, 20, 20), "points")) +
153+
ggplot2::theme(text = ggplot2::element_text(size = 24)) +
154+
ggplot2::coord_cartesian(clip = F)
124155
}
125156
if (requireNamespace("gridExtra", quietly = TRUE)) {
126157
do.call(
@@ -349,6 +380,7 @@ plot_fds = function(
349380
fraction = seq_along(varsorderedscaled) / length(varsorderedscaled),
350381
variance = varsorderedscaled
351382
)
383+
maxval = max(varsorderedscaled)
352384
plot_obj = ggplot2::ggplot(df, ggplot2::aes(x = fraction, y = variance)) +
353385
ggplot2::geom_line(color = "blue", linewidth = 1) +
354386
ggplot2::geom_vline(
@@ -361,9 +393,36 @@ plot_fds = function(
361393
linetype = "dashed",
362394
color = "red"
363395
) +
396+
ggplot2::geom_hline(
397+
yintercept = maxval,
398+
linetype = "dashed",
399+
color = "black"
400+
) +
401+
ggplot2::annotate(
402+
"text",
403+
label = sprintf("Mid PV: %0.3f", midval),
404+
x = 0,
405+
hjust = 0.0,
406+
y = midval,
407+
vjust = -0.25,
408+
fontface = "bold",
409+
size = 6,
410+
color = "red"
411+
) +
412+
ggplot2::annotate(
413+
"text",
414+
label = sprintf("Max PV: %0.3f", maxval),
415+
x = 0,
416+
hjust = 0.0,
417+
y = maxval,
418+
vjust = -0.25,
419+
size = 6,
420+
color = "black",
421+
fontface = "bold",
422+
) +
364423
ggplot2::scale_x_continuous(
365424
limits = c(0, 1),
366-
expand = ggplot2::expansion(mult = 0)
425+
expand = c(0, 0.0)
367426
) +
368427
ggplot2::scale_y_continuous(
369428
limits = c(0, maxyaxis),
@@ -373,7 +432,10 @@ plot_fds = function(
373432
x = description,
374433
y = "Prediction Variance"
375434
) +
376-
ggplot2::theme_minimal()
435+
ggplot2::theme_minimal() +
436+
ggplot2::theme(margins = ggplot2::unit(c(20, 20, 20, 20), "points")) +
437+
ggplot2::theme(text = ggplot2::element_text(size = 24)) +
438+
ggplot2::coord_cartesian(clip = F)
377439
print(plot_obj)
378440
return(invisible(varsorderedscaled))
379441
}

R/skprGUI.R

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,18 +2591,22 @@ skprGUI = function(
25912591
) |>
25922592
bindEvent(powerresultssurv())
25932593

2594-
output$aliasplot = renderPlot({
2595-
req(runmatrix(), cancelOutput = TRUE)
2596-
if (displayed_design_number_factors() > 1) {
2597-
print(runmatrix())
2598-
runmatrix() %>%
2599-
plot_correlations()
2600-
}
2601-
}) |>
2602-
bindEvent(runmatrix(), ignoreInit = TRUE)
2594+
output$aliasplot = renderPlot(
2595+
{
2596+
req(runmatrix(), cancelOutput = TRUE)
2597+
if (displayed_design_number_factors() > 1) {
2598+
runmatrix() %>%
2599+
plot_correlations() +
2600+
ggplot2::theme(text = ggplot2::element_text(size = 12))
2601+
}
2602+
},
2603+
width = fdsplot_width
2604+
) |>
2605+
bindEvent(input$evalbutton, ignoreInit = TRUE)
26032606

26042607
output$fdsplot = renderPlot(
26052608
{
2609+
req(runmatrix(), cancelOutput = TRUE)
26062610
runmatrix() %>%
26072611
plot_fds()
26082612
},

man/build_code_pane_html.Rd

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/create_code_pane_reactives.Rd

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)