Thank you Both very much Maurizio/@MAgojam and @reason180.
Code: Select all
# Data setup
library(tidyverse)
residuals <- data.frame(
Ethnicity = c("Malay", "Chinese", "Indian"),
A = c(-1.0612, -2.0538, 2.9438),
B = c(-0.47996, 0.047839, 0.40734),
C = c(1.233, 1.8845, -2.9457)
)
# p-values
compute_p <- function(x) pchisq(x^2, df = 1, lower.tail = FALSE)
raw_p <- as.data.frame(lapply(residuals[ , 2:4], compute_p))
holm_df <- data.frame(matrix(p.adjust(unlist(raw_p), method = "holm"), nrow = 3, byrow = FALSE))
bonf_df <- data.frame(matrix(p.adjust(unlist(raw_p), method = "bonferroni"), nrow = 3, byrow = FALSE))
colnames(holm_df) <- colnames(raw_p)
colnames(bonf_df) <- colnames(raw_p)
# Formatting p-values with asterisks
add_stars <- function(p) {
ifelse(p < 0.001, "***", ifelse(p < 0.01, "**", ifelse(p < 0.05, "*", "")))
}
format_with_stars <- function(p) sprintf("%.5f%s", p, add_stars(p))
raw_p_fmt <- data.frame(lapply(raw_p, format_with_stars), stringsAsFactors = FALSE)
holm_fmt <- data.frame(lapply(holm_df, format_with_stars), stringsAsFactors = FALSE)
bonf_fmt <- data.frame(lapply(bonf_df, format_with_stars), stringsAsFactors = FALSE)
# Combine everything
rownames_combined <- c(
paste0(residuals$Ethnicity[1], "_adjusted_residuals"),
paste0(residuals$Ethnicity[1], "_raw_p_values"),
paste0(residuals$Ethnicity[1], "_p_values_Holm"),
paste0(residuals$Ethnicity[1], "_p_values_Bonferroni"),
paste0(residuals$Ethnicity[2], "_adjusted_residuals"),
paste0(residuals$Ethnicity[2], "_raw_p_values"),
paste0(residuals$Ethnicity[2], "_p_values_Holm"),
paste0(residuals$Ethnicity[2], "_p_values_Bonferroni"),
paste0(residuals$Ethnicity[3], "_adjusted_residuals"),
paste0(residuals$Ethnicity[3], "_raw_p_values"),
paste0(residuals$Ethnicity[3], "_p_values_Holm"),
paste0(residuals$Ethnicity[3], "_p_values_Bonferroni")
)
final_matrix <- rbind(
residuals[1, 2:4],
raw_p_fmt[1, ],
holm_fmt[1, ],
bonf_fmt[1, ],
residuals[2, 2:4],
raw_p_fmt[2, ],
holm_fmt[2, ],
bonf_fmt[2, ],
residuals[3, 2:4],
raw_p_fmt[3, ],
holm_fmt[3, ],
bonf_fmt[3, ]
)
# Create final dataframe
final_df <- cbind(Row = rownames_combined, final_matrix)
rownames(final_df) <- NULL
I have done some calculations above (based on YT video data) and got this:
https://imgur.com/a/vgFbzvF
By the way: how to insert a picture so it is positioned in the post like beneath this text ?
Check this and correct please if I am wrong.
I have read this as well:
viewtopic.php?t=70,
and that:
viewtopic.php?f=12&t=822
and Maurizo wrote there:
I may ask you, but if you are interested in understanding the relationship between all three of your categorical variables without one necessarily being the "response", haven't you thought about trying a loglinear model?
So I would like to ask about that log-linear model as an alternative to chi square post hoc test, what are the advantages/benefits of using this ?
best regards and thank you,
Andrzej