library(metafor)
## Warning: package 'metafor' was built under R version 4.2.3
## Loading required package: Matrix
## Loading required package: metadat
## Warning: package 'metadat' was built under R version 4.2.3
## Loading required package: numDeriv
## 
## Loading the 'metafor' package (version 4.0-0). For an
## introduction to the package please type: help(metafor)
library(meta)
## Warning: package 'meta' was built under R version 4.2.3
## Loading 'meta' package (version 6.2-1).
## Type 'help(meta)' for a brief overview.
## Readers of 'Meta-Analysis with R (Use R!)' should install
## older version of 'meta' package: https://tinyurl.com/dt4y5drs
df <- read.csv("Online.csv")
View(df)

Draw Histogram

library(ggplot2)
hedges_g <- df$hedges_g
# calculate the mean and median values
mean_val <- mean(hedges_g)
median_val <- median(hedges_g)

# create a histogram of the effect size coefficients
ggplot(data.frame(hedges_g), aes(x = hedges_g)) +
  geom_histogram(binwidth = 0.1, fill = "blue", alpha = 0.5) +
  geom_vline(xintercept = mean_val, color = "red", linetype = "dashed") +
  geom_vline(xintercept = median_val, color = "green", linetype = "dotted") +
  labs(title = "Histogram of Hedges' g Effect Size Coefficients",
       x = "Hedges' g",
       y = "Frequency")

# Perform Q Statics (Research Question 1)

meta <- rma(yi = hedges_g, sei = Standard_Error, data = df)
summary(meta)
## 
## Random-Effects Model (k = 79; tau^2 estimator: REML)
## 
##    logLik   deviance        AIC        BIC       AICc   
## -131.7527   263.5054   267.5054   272.2188   267.6654   
## 
## tau^2 (estimated amount of total heterogeneity): 1.6020 (SE = 0.2854)
## tau (square root of estimated tau^2 value):      1.2657
## I^2 (total heterogeneity / total variability):   96.97%
## H^2 (total variability / sampling variability):  33.03
## 
## Test for Heterogeneity:
## Q(df = 78) = 20020.7208, p-val < .0001
## 
## Model Results:
## 
## estimate      se     zval    pval    ci.lb   ci.ub    
##  -0.1185  0.1518  -0.7806  0.4350  -0.4160  0.1790    
## 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Research Question 1

# Create a data frame with your effect sizes and standard errors
data <- data.frame(hedges_g = df$hedges_g,
                   se = df$Standard_Error)

# Calculate the average effect size
avg_effect_size <- mean(data$hedges_g)

# Calculate the variance of the effect sizes
var_effect_sizes <- sum((data$hedges_g - avg_effect_size)^2) / (nrow(data) - 1)

# Calculate the standard error of the effect sizes
se_effect_sizes <- sqrt(var_effect_sizes / nrow(data))

# Calculate the z-values for each effect size
z_values <- (data$hedges_g - 0) / data$se

# Calculate the p-values for each z-value
p_values <- 2 * (1 - pnorm(abs(z_values)))

# Calculate the 95% confidence interval for the effect sizes
lower_bound <- data$hedges_g - (1.96 * data$se)
upper_bound <- data$hedges_g + (1.96 * data$se)

# Print the results
cat("Average effect size:", avg_effect_size, "
")
## Average effect size: -0.1096203
cat("Variance of effect sizes:", var_effect_sizes, "
")
## Variance of effect sizes: 1.484583
cat("Standard error of effect sizes:", se_effect_sizes, "
")
## Standard error of effect sizes: 0.1370846
cat("Average z-value of effect sizes:", mean(z_values), "
")
## Average z-value of effect sizes: -1.072208
cat("Avergae p-values of effect sizes:", mean(p_values), "
")
## Avergae p-values of effect sizes: 0.3098071
cat("Average 95% confidence interval lower bound:", mean (lower_bound), "
")
## Average 95% confidence interval lower bound: -1.005514
cat("Average 95% confidence interval upper bound:", mean(upper_bound), "
")
## Average 95% confidence interval upper bound: 0.7862734

Research Question 2

library(metafor)
# Calculate the number of effect sizes for each institution type
n <- tapply(df$hedges_g, df$Course_Subject, length)
n
##               Business             Humanities Information Technology 
##                     27                      8                      8 
##                  Other             Statistics 
##                     20                     16
# Calculate the average effect size for each institution type
mean <- tapply(df$hedges_g, df$Course_Subject, mean)
mean
##               Business             Humanities Information Technology 
##              0.1677778             -0.3200000              0.2150000 
##                  Other             Statistics 
##              0.0200000             -0.7968750
# Calculate the variance of effect sizes for each institution type
variance <- tapply(df$hedges_g, df$Course_Subject, var)
variance
##               Business             Humanities Information Technology 
##              0.4798333              0.1127714              0.1041429 
##                  Other             Statistics 
##              4.6140000              0.1979696
# Calculate the standard error of effect sizes for each institution type
se <- sqrt(variance / n)

# Calculate the z-values for each institution type
z <- mean / se

# Calculate the p-values for each institution type (two-tailed test)
p <- 2 * (1 - pnorm(abs(z)))

# Calculate the 95% confidence interval lower bound and upper bound for each institution type
ci_lower <- mean - qt(0.975, n-1) * se
ci_upper <- mean + qt(0.975, n-1) * se

# Combine the results into a data frame
results <- data.frame(institution = unique(df$Course_Subject), n = n, mean = mean, variance = variance, se = se, z = z, p = p, ci_lower = ci_lower, ci_upper = ci_upper)

# Print the results
results
##                                   institution  n       mean  variance        se
## Business                                Other 27  0.1677778 0.4798333 0.1333102
## Humanities                           Business  8 -0.3200000 0.1127714 0.1187284
## Information Technology             Humanities  8  0.2150000 0.1041429 0.1140958
## Other                  Information Technology 20  0.0200000 4.6140000 0.4803124
## Statistics                         Statistics 16 -0.7968750 0.1979696 0.1112344
##                                  z            p    ci_lower    ci_upper
## Business                1.25855185 2.081922e-01 -0.10624523  0.44180078
## Humanities             -2.69522751 7.034058e-03 -0.60074801 -0.03925199
## Information Technology  1.88438097 5.951346e-02 -0.05479375  0.48479375
## Other                   0.04163957 9.667860e-01 -0.98530540  1.02530540
## Statistics             -7.16392382 7.840395e-13 -1.03396558 -0.55978442

Research Question 3

# Calculate the number of effect sizes for each institution type
n <- tapply(df$hedges_g, df$Institution_Type, length)
n
##      Graduate Undergraduate 
##            11            68
# Calculate the average effect size for each institution type
mean <- tapply(df$hedges_g, df$Institution_Type, mean)
mean
##      Graduate Undergraduate 
##   -0.42545455   -0.05852941
# Calculate the variance of effect sizes for each institution type
variance <- tapply(df$hedges_g, df$Institution_Type, var)
variance
##      Graduate Undergraduate 
##     7.6983473     0.5602874
# Calculate the standard error of effect sizes for each institution type
se <- sqrt(variance / n)

# Calculate the z-values for each institution type
z <- mean / se

# Calculate the p-values for each institution type (two-tailed test)
p <- 2 * (1 - pnorm(abs(z)))

# Calculate the 95% confidence interval lower bound and upper bound for each institution type
ci_lower <- mean - qt(0.975, n-1) * se
ci_upper <- mean + qt(0.975, n-1) * se

# Combine the results into a data frame
results <- data.frame(institution = unique(df$Institution_Type), n = n, mean = mean, variance = variance, se = se, z = z, p = p, ci_lower = ci_lower, ci_upper = ci_upper)

# Print the results
results
##                 institution  n        mean  variance        se          z
## Graduate           Graduate 11 -0.42545455 7.6983473 0.8365702 -0.5085700
## Undergraduate Undergraduate 68 -0.05852941 0.5602874 0.0907718 -0.6447973
##                       p   ci_lower  ci_upper
## Graduate      0.6110536 -2.2894492 1.4385401
## Undergraduate 0.5190586 -0.2397107 0.1226519

test for heterogeneity based on institution type

# fit a random-effects model with Institution_Type as the moderator
library(metafor)
model_inst <- rma(yi = hedges_g, sei = Standard_Error, mods = ~ Institution_Type, data = df, method = "REML")
Q_inst <- summary(model_inst)$QE[1]
Q_inst
## [1] 14620.8

test for heterogeneity based on Course Subject

# fit a random-effects model with Course_Subject_Type as the moderator
model_course <- rma(yi = hedges_g, sei = Standard_Error, mods = ~ Course_Subject, data = df, method = "REML")
Q_inst <- summary(model_course)$QE[1]
Q_inst
## [1] 18356.4