knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
We load the necessary packages as well as the data set for the example. Because for this example we are using only complete data we remove the the two studies with NA
(i.e., Study 6 and Study 17).
library(mars) becker09 <- na.omit(becker09) # ommiting studies with NA
Next, we create a list, which will be imputed in our other functions.
becker09_list <- df_to_corr(becker09, variables = c('Cognitive_Performance', 'Somatic_Performance', 'Selfconfidence_Performance', 'Somatic_Cognitive', 'Selfconfidence_Cognitive', 'Selfconfidence_Somatic'), ID = 'ID')
There are currently three options for the variance-covariance matrix of the correlation matrix (i.e, simple, average, and weighted) for this example we selected the weighted option.
#olkin_siotani(becker09_list, becker09$N, type = 'simple') #olkin_siotani(becker09_list, becker09$N, type = 'average') olkin_siotani(becker09_list, becker09$N, type = 'weighted')
The function below creates and organize elements that are then fitted internally into the metafor
package. Below we fitted fixed and random-effects models and extracted some more detail information from objects that are not directly output by the functions.
First, we see results under fixed-effect models.
mars(data = becker09, studyID = 'ID', effectID = 'numID', sample_size = 'N', effectsize_type = 'cor', estimation_method = 'FE', varcov_type = 'weighted', variable_names = c('Cognitive_Performance', 'Somatic_Performance', 'Selfconfidence_Performance', 'Somatic_Cognitive', 'Selfconfidence_Cognitive', 'Selfconfidence_Somatic')) |> summary()
Now we fit a random-effects model and extract some objects from this output.
model_out_random <- mars(data = becker09, studyID = 'ID', effectID = 'numID', sample_size = 'N', effectsize_type = 'cor', varcov_type = 'weighted', variable_names = c('Cognitive_Performance', 'Somatic_Performance', 'Selfconfidence_Performance', 'Somatic_Cognitive', 'Selfconfidence_Cognitive', 'Selfconfidence_Somatic')) summary(model_out_random)
Now, we are ready to input the average correlation matrix and its variance covariance matrix and our own function to appropriate estimate SE via the multivariate delta method.
model <- "## Regression paths Performance ~ Cognitive + Somatic + Selfconfidence Selfconfidence ~ Cognitive + Somatic " mars(data = becker09, studyID = 'ID', effectID = 'numID', sample_size = 'N', effectsize_type = 'cor', varcov_type = 'weighted', variable_names = c('Cognitive_Performance', 'Somatic_Performance', 'Selfconfidence_Performance', 'Somatic_Cognitive', 'Selfconfidence_Cognitive', 'Selfconfidence_Somatic')) |> path_model(model = model) |> summary()
We now subset the data to obtain results only for the studies that reported on Team sports.
becker09_T <- subset(becker09, becker09$Team == "T")
mars(data = becker09_T, studyID = 'ID', effectID = 'numID', sample_size = 'N', effectsize_type = 'cor', varcov_type = 'weighted', variable_names = c('Cognitive_Performance', 'Somatic_Performance', 'Selfconfidence_Performance', 'Somatic_Cognitive', 'Selfconfidence_Cognitive', 'Selfconfidence_Somatic')) |> summary() # random_model2 <- fit_model(data = input_metafor2, effect_size = 'yi', # var_cor = 'V', moderators = ~ -1 + factor(outcome), # random_params = ~ factor(outcome) | factor(study))
model <- "## Regression paths Performance ~ Cognitive + Somatic + Selfconfidence Selfconfidence ~ Cognitive + Somatic " mars(data = becker09_T, studyID = 'ID', effectID = 'numID', sample_size = 'N', effectsize_type = 'cor', varcov_type = 'weighted', variable_names = c('Cognitive_Performance', 'Somatic_Performance', 'Selfconfidence_Performance', 'Somatic_Cognitive', 'Selfconfidence_Cognitive', 'Selfconfidence_Somatic')) |> path_model(model = model) |> summary()
Similarly, we now subset the data to obtain results only for the studies that reported on Individual sports.
becker09_I <- subset(becker09, becker09$Team == "I")
mars(data = becker09_I, studyID = 'ID', effectID = 'numID', sample_size = 'N', effectsize_type = 'cor', varcov_type = 'weighted', variable_names = c('Cognitive_Performance', 'Somatic_Performance', 'Selfconfidence_Performance', 'Somatic_Cognitive', 'Selfconfidence_Cognitive', 'Selfconfidence_Somatic')) |> summary() # random_model3 <- fit_model(data = input_metafor3, effect_size = 'yi', # var_cor = 'V', moderators = ~ -1 + factor(outcome), # random_params = ~ factor(outcome) | factor(study))
model <- "## Regression paths Performance ~ Cognitive + Somatic + Selfconfidence Selfconfidence ~ Cognitive + Somatic " mars(data = becker09_I, studyID = 'ID', effectID = 'numID', sample_size = 'N', effectsize_type = 'cor', varcov_type = 'weighted', variable_names = c('Cognitive_Performance', 'Somatic_Performance', 'Selfconfidence_Performance', 'Somatic_Cognitive', 'Selfconfidence_Cognitive', 'Selfconfidence_Somatic')) |> path_model(model = model) |> summary()
Here we compute the synthetic partial correlation from the average correlation matrix.
# partial corr matrix part_cor <- round(corpcor::vec2sm(model_out_random$beta_r),3) diag(part_cor) <- 1 part_cor # var-cov matrix of partials Psy <- model_out_random$varcov_beta round(var_path(model_out_random$beta_r, Psy, type = 'pcor'), 4)
Here we work with partial correlation for each study and then synthesize that information.
#--------------------------------------------------------------------- # Create a data set with 8 complete studies #--------------------------------------------------------------------- R <- becker09_list R$"6" <- NULL R$"17" <- NULL n <- becker09$N[c(-3, -5)] #------------------------------------------------------------------ # first replace NA by zeros RR <- R # redifine list PR <- lapply(RR, cor2pcor) pr <- unlist(lapply(PR, '[[', 4)) var_pr <- (1-pr^2)^2 / (n - 3 -1) rma.uni(pr, var_pr)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.