knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(metaRmat)

becker09 
becker09_list <- df_to_corr(becker09, 
                            variables = c('Cognitive_Performance',
                                          'Somatic_Performance',
                                          'Selfconfidence_Performance', 
                                          'Somatic_Cognitive',
                                          'Selfconfidence_Cognitive',
                                          'Selfconfidence_Somatic'),
                            ID = 'ID')

Calculate OS

olkin_siotani(becker09_list, becker09$N, type = 'simple')
olkin_siotani(becker09_list, becker09$N, type = 'average')
olkin_siotani(becker09_list, becker09$N, type = 'weighted')

Master Prep Data Function

input_metafor <- prep_data(becker09, becker09$N, type = 'weighted', 
          variable_names = c('Cognitive_Performance', 'Somatic_Performance',
                             'Selfconfidence_Performance', 
                             'Somatic_Cognitive',
                             'Selfconfidence_Cognitive',
                             'Selfconfidence_Somatic'),
          ID = 'ID')
fixed_model <- fit_model(data = input_metafor, effect_size = 'yi', 
          var_cor = 'V', moderators = ~ -1 + factor(outcome), 
          random_params = NULL)
random_model <- fit_model(data = input_metafor, effect_size = 'yi', 
          var_cor = 'V', moderators = ~ -1 + factor(outcome), 
          random_params = ~ factor(outcome) | factor(study))

Extract model data

model_out_fixed <- extract_model(fixed_model, 
                                 variable_names = c('Cognitive_Performance',
                                                    'Somatic_Performance',
                                                    'Selfconfidence_Performance', 
                                                    'Somatic_Cognitive',
                                                    'Selfconfidence_Cognitive',
                                                    'Selfconfidence_Somatic'))
model_out_random <- extract_model(random_model, 
                                  variable_names = c('Cognitive_Performance',
                                                     'Somatic_Performance',
                                                     'Selfconfidence_Performance', 
                                                     'Somatic_Cognitive',
                                                     'Selfconfidence_Cognitive',
                                                     'Selfconfidence_Somatic'))

Fit model with lavaan

model <- "## Regression paths
          Performance ~ Cognitive + Somatic + Selfconfidence
          Selfconfidence ~ Cognitive + Somatic"

path_output <- path_model(data = model_out_random, model = model, 
                          num_obs = 600)
summary(path_output)

Fit reduced model

model <- "## Regression paths
          Performance ~ Cognitive + Somatic"

path_output <- path_model(data = model_out_random, model = model, 
                            num_obs = 600)
summary(path_output)

Functions work with pipe %>%

library(dplyr)

model <- "## Regression paths
          Performance ~ Cognitive + Somatic + Selfconfidence
          Selfconfidence ~ Cognitive + Somatic"

prep_data(becker09, becker09$N, type = 'weighted', 
          variable_names = c('Cognitive_Performance', 'Somatic_Performance',
                             'Selfconfidence_Performance', 
                             'Somatic_Cognitive',
                             'Selfconfidence_Cognitive',
                             'Selfconfidence_Somatic'),
          ID = 'ID') %>%
  fit_model(effect_size = 'yi', 
          var_cor = 'V', moderators = ~ -1 + factor(outcome), 
          random_params = ~ factor(outcome) | factor(study),
          structure = 'UN') %>%
  extract_model(variable_names = c('Cognitive_Performance',
                                   'Somatic_Performance',
                                   'Selfconfidence_Performance', 
                                   'Somatic_Cognitive',
                                   'Selfconfidence_Cognitive',
                                   'Selfconfidence_Somatic')) %>%
  path_model(model = model, num_obs = 600) %>% 
  summary()


lebebr01/metaRmat documentation built on Feb. 24, 2024, 10:44 a.m.