Skip to content

Commit

Permalink
Make scores and results columns uniform
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgirard committed Oct 25, 2024
1 parent f9e9705 commit 8c08945
Show file tree
Hide file tree
Showing 20 changed files with 250 additions and 338 deletions.
5 changes: 2 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ S3method(as_radian,default)
S3method(print,circumplex_instrument)
S3method(print,circumplex_ssm)
S3method(quantile,circumplex_radian)
S3method(ssm_plot_scores,circumplex_ssm)
S3method(ssm_plot_scores,data.frame)
S3method(summary,circumplex_instrument)
S3method(summary,circumplex_ssm)
export(PANO)
Expand All @@ -30,7 +28,8 @@ export(scales)
export(score)
export(ssm_analyze)
export(ssm_parameters)
export(ssm_plot)
export(ssm_plot_circle)
export(ssm_plot_contrast)
export(ssm_plot_scores)
export(ssm_score)
export(ssm_table)
Expand Down
46 changes: 26 additions & 20 deletions R/ssm_analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,19 @@ ssm_analyze_means <- function(data, scales, angles, grouping, contrast,
grp <- as.integer(bs_input[[ncol(bs_input)]])
scores <- mean_scores(mat, grp, listwise)
colnames(scores) <- scales_names
group_levels <- levels(bs_input[[ncol(bs_input)]])
if (contrast) {
scores <- rbind(scores, scores[2, ] - scores[1, ])
scores <- cbind(
label = c(group_levels, paste0(group_levels[[2]], " - ", group_levels[[1]])),
as.data.frame(scores)
)
} else {
scores <- cbind(label = group_levels, as.data.frame(scores))
}
scores <- as.data.frame(scores)
Group <- group_levels
Measure <- rep(NA_character_, times = n_groups)
if (contrast && !is.null(grouping)) {
Group <- c(Group, paste0(Group[[2]], " - ", Group[[1]]))
Measure <- c(Measure, Measure[[1]])
}
Label <- Group
scores <- cbind(Label, Group, Measure, scores)

# Create function that will perform bootstrapping
bs_function <- function(.data, index, scales, angles, contrast, listwise, ...) {
Expand All @@ -240,15 +244,15 @@ ssm_analyze_means <- function(data, scales, angles, grouping, contrast,
strata = bs_input[[ncol(bs_input)]]
)

# Select and label results
row_labels <- group_levels
if (contrast) {
row_labels <- c(
row_labels,
paste0(group_levels[[2]], " - ", group_levels[[1]])
)
params <- bs_output
Group <- group_levels
Measure <- rep(NA_character_, times = n_groups)
if (contrast && !is.null(grouping)) {
Group <- c(Group, paste0(Group[[2]], " - ", Group[[1]]))
Measure <- c(Measure, Measure[[1]])
}
results <- cbind(label = row_labels, bs_output)
Label <- Group
results <- cbind(Label, Group, Measure, params)

# Collect analysis details
details <- list(
Expand Down Expand Up @@ -330,12 +334,13 @@ ssm_analyze_corrs <- function(data, scales, angles, measures, grouping,
Group <- c(Group, paste0(Group[[2]], " - ", Group[[1]]))
Measure <- c(Measure, Measure[[1]])
}
scores <- cbind(Group, Measure, scores)
if (is.null(grouping)) {
scores$label <- Measure
Label <- Measure
} else {
scores$label <- paste0(Measure, ": ", Group)
Label <- paste0(Measure, ": ", Group)
}
scores <- cbind(Label, Group, Measure, scores)


# Create function that will perform bootstrapping
bs_function <- function(.data, index, scales, measures, angles, contrast,
Expand Down Expand Up @@ -371,12 +376,13 @@ ssm_analyze_corrs <- function(data, scales, angles, measures, grouping,
Group <- c(Group, paste0(Group[[2]], " - ", Group[[1]]))
Measure <- c(Measure, Measure[[1]])
}
results <- cbind(Group, Measure, bs_output)
if (is.null(grouping)) {
results$label <- Measure
Label <- Measure
} else {
results$label <- paste0(Measure, ": ", Group)
Label <- paste0(Measure, ": ", Group)
}
results <- cbind(Label, Group, Measure, bs_output)


# Collect analysis details
details <- list(
Expand Down
2 changes: 1 addition & 1 deletion R/ssm_oop.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ print.circumplex_ssm <- function(x, digits = 3, ...) {
yes = "Contrast",
no = "Profile"
)
cat("\n# ", results_type, " [", dat$label, "]:\n\n",
cat("\n# ", results_type, " [", dat$Label, "]:\n\n",
sep = ""
)
print.default(m, print.gap = 3L, na.print = "")
Expand Down
Loading

0 comments on commit 8c08945

Please sign in to comment.