A Basic Example

Read in the data

To start, load the relevant models using the readModels() function from the MplusAutomation package. Before loading in the data, ensure there are no special characters such as brackets, dashes, or spaces, which prevent dataset titles from being formatted correctly. This also causes further issues down the line. You can quickly rename all your model output files using the function below. This will remove any special characters that might cause issues later.

# Note: set your working directory to the folder your models are located in.
fix_file_names(dir)

The original files:

original_files
#> [1] "test-file-1.out" "test file 2.out" "test(file)3.out"

The renamed files:

renamed_files
#> [1] "test_file_1.out" "test_file_2.out" "test_file_3.out"

After this has been completed, load in your data. In this example we will be loading in a set of univariate models which include the predictor variables Negative Affect (na) and Positive Affect (pa), and the outcome variables depression (DEPR) and satisfaction with life (SWL). Always include recursive = TRUE, even if all your files are located in one folder, as this will ensure that the dataset titles format properly.

models <- readModels(dir, recursive = TRUE)
#> Reading model:  univariate_models/predictDEP/naAR predict DEPR/1_naAR_CESD.out 
#> Reading model:  univariate_models/predictDEP/naAR predict DEPR/2_naAR_CESD.out 
#> Reading model:  univariate_models/predictDEP/naAR predict DEPR/3_naAR_QIDS.out 
#> Reading model:  univariate_models/predictDEP/paAR predict DEPR/1_paAR_CESD.out 
#> Reading model:  univariate_models/predictDEP/paAR predict DEPR/2_paAR_CESD.out 
#> Reading model:  univariate_models/predictDEP/paAR predict DEPR/3_paAR_QIDS.out 
#> Reading model:  univariate_models/predictSWL/naAR predict SWL/1_naAR_SWL.out 
#> Reading model:  univariate_models/predictSWL/naAR predict SWL/2_naAR_SWL.out 
#> Reading model:  univariate_models/predictSWL/naAR predict SWL/3_naAR_SWL.out 
#> Reading model:  univariate_models/predictSWL/paAR predict SWL/1_paAR_SWL.out 
#> Reading model:  univariate_models/predictSWL/paAR predict SWL/2_paAR_SWL.out 
#> Reading model:  univariate_models/predictSWL/paAR predict SWL/3_paAR_SWL.out

The models read in by the readModels() function will be saved as a list. The structure of each of the models is similar to that shown below. The collation function mplus_compile extracts data primarily from the section called ‘parameters’. This structure is only displayed to show how the model output is read into R via readModels() and where the collated data in mplus_compile() comes from.

#>                         levelName
#> 1  Root                          
#> 2   ¦--input                     
#> 3   ¦   ¦--data                  
#> 4   ¦   ¦--variable              
#> 5   ¦   °--analysis              
#> 6   ¦--warnings                  
#> 7   ¦--errors                    
#> 8   ¦--data_summary              
#> 9   ¦   °--overall               
#> 10  ¦--sampstat                  
#> 11  ¦--summaries                 
#> 12  ¦--invariance_testing        
#> 13  ¦--parameters                
#> 14  ¦   ¦--unstandardized        
#> 15  ¦   ¦--r2                    
#> 16  ¦   ¦--ci.unstandardized     
#> 17  ¦   ¦--stdyx.standardized    
#> 18  ¦   ¦--ci.stdyx.standardized 
#> 19  ¦   °--wilevel.standardized  
#> 20  ¦       ¦--stdyx.standardized
#> 21  ¦       °--r2                
#> 22  ¦--class_counts              
#> 23  ¦--indirect                  
#> 24  ¦--residuals                 
#> 25  ¦--tech1                     
#> 26  ¦   ¦--parameterSpecification
#> 27  ¦   ¦   ¦--WITHIN            
#> 28  ¦   ¦   °--BETWEEN           
#> 29  ¦   °--startingValues        
#> 30  ¦       ¦--WITHIN            
#> 31  ¦       °--BETWEEN           
#> 32  °--tech3

Creating a Tidy Dataset

The first aim of MplusReadR is to tabulate key output from these Mplus files. Using the default settings will result in a tibble that displays all columns present in the standardized section of the ‘parameters’ section of an Mplus file (as shown in the structure above) to three decimal places (as shown below). Use ?mplus_compile or head to the reference page for mplus_compile to check the default options and learn about ways you can customise output.

tidy_data <- mplus_compile(Mplus_file = models)
tidy_data
#> # A tibble: 216 x 13
#>    dataset dataset_title     T     N paramHeader param est   posterior_sd pval 
#>      <int> <chr>         <dbl> <dbl> <chr>       <chr> <chr> <chr>        <chr>
#>  1       1 1_naAR_CESD    2808    94 NAONNA|NA.~ NA&1  0.20  0.02         0.00 
#>  2       1 1_naAR_CESD    2808    94 NAVAR.|     NA    0.92  0.01         0.00 
#>  3       1 1_naAR_CESD    2808    94 Z.ON        NAON~ 0.35  0.15         0.01 
#>  4       1 1_naAR_CESD    2808    94 Z.ON        NAVAR 0.14  0.11         0.11 
#>  5       1 1_naAR_CESD    2808    94 Z.ON        NA    0.42  0.11         0.00 
#>  6       1 1_naAR_CESD    2808    94 NA.WITH     NAON~ 0.22  0.16         0.10 
#>  7       1 1_naAR_CESD    2808    94 NA.WITH     NAVAR -0.23 0.12         0.03 
#>  8       1 1_naAR_CESD    2808    94 NAONNA.WITH NAVAR -0.13 0.17         0.23 
#>  9       1 1_naAR_CESD    2808    94 Means       NA    2.26  0.21         0.00 
#> 10       1 1_naAR_CESD    2808    94 Means       NAON~ 1.08  0.26         0.00 
#> # ... with 206 more rows, and 4 more variables: lower_2.5ci <chr>,
#> #   upper_2.5ci <chr>, sig <lgl>, BetweenWithin <chr>

Creating a html APA-style table

The second aim of MplusReadR is to format the tabulated Mplus output created above into a html APA-style table. The default behaviour of this function is to apply 12 point Times New Roman and general APA table formatting, with estimates and confidence intervals merged together, as shown below. Note this only shows a subset of the data.

# Creating a subset of the tidy data
tidy_data_short <- tidy_data %>% slice(1:3, 37:39)

# Generating a APA-style html table
table <- mplus_apa_table(data = tidy_data_short) 
table
dataset dataset_title T N paramHeader param posterior_sd pval sig BetweenWithin value
1 1 1_naAR_CESD 2808 94 NAONNA|NA.ON NA&1 0.02 0.00 TRUE Within.Std.Averaged.Over.Clusters 0.20
[0.16, 0.24]
2 1 1_naAR_CESD 2808 94 NAVAR.| NA 0.01 0.00 TRUE Within.Std.Averaged.Over.Clusters 0.92
[0.90, 0.95]
3 1 1_naAR_CESD 2808 94 Z.ON NAONNA 0.15 0.01 TRUE Between 0.35
[0.06, 0.63]
4 3 3_naAR_QIDS 12355 118 NAONNA|NA.ON NA&1 0.01 0.00 TRUE Within.Std.Averaged.Over.Clusters 0.38
[0.36, 0.41]
5 3 3_naAR_QIDS 12355 118 NAVAR.| NA 0.01 0.00 TRUE Within.Std.Averaged.Over.Clusters 0.82
[0.80, 0.84]
6 3 3_naAR_QIDS 12355 118 Z.ON NAONNA 0.08 0.27 FALSE Between 0.05
[-0.11, 0.21]

You can save the html table using the code below. Replace the x with the name of your table and specify the name of the file, ensuring the .html is kept at the end and the line separator (sep) stays the same.

write(x = table, file = "table.html", sep = "\n") 

Example 2: Customising the collated output

There are several ways to customise the collated output created by mplus_compile().

Display Options

There are multiple column display options, which can be toggled using the display parameter. These are display = "minimal" and display = "descriptives".

mplus_compile(Mplus_file = models, display = "minimal")
#> # A tibble: 216 x 7
#>    dataset dataset_title paramHeader  param  est   lower_2.5ci upper_2.5ci
#>      <int> <chr>         <chr>        <chr>  <chr> <chr>       <chr>      
#>  1       1 1_naAR_CESD   NAONNA|NA.ON NA&1   0.20  0.16        0.24       
#>  2       1 1_naAR_CESD   NAVAR.|      NA     0.92  0.90        0.95       
#>  3       1 1_naAR_CESD   Z.ON         NAONNA 0.35  0.06        0.63       
#>  4       1 1_naAR_CESD   Z.ON         NAVAR  0.14  -0.08       0.36       
#>  5       1 1_naAR_CESD   Z.ON         NA     0.42  0.21        0.63       
#>  6       1 1_naAR_CESD   NA.WITH      NAONNA 0.22  -0.10       0.54       
#>  7       1 1_naAR_CESD   NA.WITH      NAVAR  -0.23 -0.45       0.00       
#>  8       1 1_naAR_CESD   NAONNA.WITH  NAVAR  -0.13 -0.46       0.21       
#>  9       1 1_naAR_CESD   Means        NA     2.26  1.84        2.66       
#> 10       1 1_naAR_CESD   Means        NAONNA 1.08  0.63        1.62       
#> # ... with 206 more rows
mplus_compile(Mplus_file = models, display = "descriptives")
#> # A tibble: 216 x 8
#>    dataset_title paramHeader      T     N param  est   lower_2.5ci upper_2.5ci
#>    <chr>         <chr>        <dbl> <dbl> <chr>  <chr> <chr>       <chr>      
#>  1 1_naAR_CESD   NAONNA|NA.ON  2808    94 NA&1   0.20  0.16        0.24       
#>  2 1_naAR_CESD   NAVAR.|       2808    94 NA     0.92  0.90        0.95       
#>  3 1_naAR_CESD   Z.ON          2808    94 NAONNA 0.35  0.06        0.63       
#>  4 1_naAR_CESD   Z.ON          2808    94 NAVAR  0.14  -0.08       0.36       
#>  5 1_naAR_CESD   Z.ON          2808    94 NA     0.42  0.21        0.63       
#>  6 1_naAR_CESD   NA.WITH       2808    94 NAONNA 0.22  -0.10       0.54       
#>  7 1_naAR_CESD   NA.WITH       2808    94 NAVAR  -0.23 -0.45       0.00       
#>  8 1_naAR_CESD   NAONNA.WITH   2808    94 NAVAR  -0.13 -0.46       0.21       
#>  9 1_naAR_CESD   Means         2808    94 NA     2.26  1.84        2.66       
#> 10 1_naAR_CESD   Means         2808    94 NAONNA 1.08  0.63        1.62       
#> # ... with 206 more rows

These can also be found using ?mplus_compile.

Alternatively, you can manually specify which columns are displayed.

mplus_compile(Mplus_file = models, 
              display = c("dataset", "dataset_title", "paramHeader", "param", "est"))
#> # A tibble: 216 x 5
#>    dataset dataset_title paramHeader  param  est  
#>      <int> <chr>         <chr>        <chr>  <chr>
#>  1       1 1_naAR_CESD   NAONNA|NA.ON NA&1   0.20 
#>  2       1 1_naAR_CESD   NAVAR.|      NA     0.92 
#>  3       1 1_naAR_CESD   Z.ON         NAONNA 0.35 
#>  4       1 1_naAR_CESD   Z.ON         NAVAR  0.14 
#>  5       1 1_naAR_CESD   Z.ON         NA     0.42 
#>  6       1 1_naAR_CESD   NA.WITH      NAONNA 0.22 
#>  7       1 1_naAR_CESD   NA.WITH      NAVAR  -0.23
#>  8       1 1_naAR_CESD   NAONNA.WITH  NAVAR  -0.13
#>  9       1 1_naAR_CESD   Means        NA     2.26 
#> 10       1 1_naAR_CESD   Means        NAONNA 1.08 
#> # ... with 206 more rows

Filtering parameters and parameter headings

As well as specifying columns, you can specify which parameters (parameter) or parameter headings (param_header) are shown.

mplus_compile(Mplus_file = models,
              display = c("dataset", "dataset_title", "paramHeader", "param", "est"),
              param_header = c("Z.ON", "NA.WITH"),
              parameter = c("NAONNA", "NAVAR"))
#> # A tibble: 30 x 5
#>    dataset dataset_title paramHeader param  est  
#>      <int> <chr>         <chr>       <chr>  <chr>
#>  1       1 1_naAR_CESD   Z.ON        NAONNA 0.35 
#>  2       1 1_naAR_CESD   Z.ON        NAVAR  0.14 
#>  3       1 1_naAR_CESD   NA.WITH     NAONNA 0.22 
#>  4       1 1_naAR_CESD   NA.WITH     NAVAR  -0.23
#>  5       1 1_naAR_CESD   NAONNA.WITH NAVAR  -0.13
#>  6       2 2_naAR_CESD   Z.ON        NAONNA -0.07
#>  7       2 2_naAR_CESD   Z.ON        NAVAR  0.05 
#>  8       2 2_naAR_CESD   NA.WITH     NAONNA 0.39 
#>  9       2 2_naAR_CESD   NA.WITH     NAVAR  0.52 
#> 10       2 2_naAR_CESD   NAONNA.WITH NAVAR  -0.04
#> # ... with 20 more rows

The function uses partial filtering, which means that all words that contain a specified string will be displayed (as shown below). This makes it easier to quickly extract multiple parameters or parameter headings, like those that end in “.WITH”. In this case it extracts NA.WITH, NAONNA.WITH, PA.WITH, etc.

mplus_compile(Mplus_file = models,
              param_header = c(".WITH"))
#> # A tibble: 36 x 13
#>    dataset dataset_title     T     N paramHeader param est   posterior_sd pval 
#>      <int> <chr>         <dbl> <dbl> <chr>       <chr> <chr> <chr>        <chr>
#>  1       1 1_naAR_CESD    2808    94 NA.WITH     NAON~ 0.22  0.16         0.10 
#>  2       1 1_naAR_CESD    2808    94 NA.WITH     NAVAR -0.23 0.12         0.03 
#>  3       1 1_naAR_CESD    2808    94 NAONNA.WITH NAVAR -0.13 0.17         0.23 
#>  4       2 2_naAR_CESD   21615   100 NA.WITH     NAON~ 0.39  0.11         0.00 
#>  5       2 2_naAR_CESD   21615   100 NA.WITH     NAVAR 0.52  0.08         0.00 
#>  6       2 2_naAR_CESD   21615   100 NAONNA.WITH NAVAR -0.04 0.13         0.37 
#>  7       3 3_naAR_QIDS   12355   118 NA.WITH     NAON~ 0.36  0.11         0.00 
#>  8       3 3_naAR_QIDS   12355   118 NA.WITH     NAVAR 0.53  0.07         0.00 
#>  9       3 3_naAR_QIDS   12355   118 NAONNA.WITH NAVAR 0.36  0.10         0.00 
#> 10       4 1_paAR_CESD    2808    94 PA.WITH     PAON~ -0.02 0.19         0.45 
#> # ... with 26 more rows, and 4 more variables: lower_2.5ci <chr>,
#> #   upper_2.5ci <chr>, sig <lgl>, BetweenWithin <chr>

The consequence is that it is possible that more parameters or parameter headings are displayed than expected. For example, if you are after the parameter “NA”, it will also display “NAONNA” or “NAVAR” as these contain “NA”.

mplus_compile(Mplus_file = models,
              display = c("dataset", "dataset_title", "paramHeader", "param", "est"),
              parameter = "NA")
#> # A tibble: 90 x 5
#>    dataset dataset_title paramHeader  param  est  
#>      <int> <chr>         <chr>        <chr>  <chr>
#>  1       1 1_naAR_CESD   NAONNA|NA.ON NA&1   0.20 
#>  2       1 1_naAR_CESD   NAVAR.|      NA     0.92 
#>  3       1 1_naAR_CESD   Z.ON         NAONNA 0.35 
#>  4       1 1_naAR_CESD   Z.ON         NAVAR  0.14 
#>  5       1 1_naAR_CESD   Z.ON         NA     0.42 
#>  6       1 1_naAR_CESD   NA.WITH      NAONNA 0.22 
#>  7       1 1_naAR_CESD   NA.WITH      NAVAR  -0.23
#>  8       1 1_naAR_CESD   NAONNA.WITH  NAVAR  -0.13
#>  9       1 1_naAR_CESD   Means        NA     2.26 
#> 10       1 1_naAR_CESD   Means        NAONNA 1.08 
#> # ... with 80 more rows

You can address this issue by using regular expressions (regex). There are many regex rules you can apply, but two useful ones are:

  • If a string STARTS with a particular set of characters, use ^.
    • So if a string starts with NA, use ^NA.
  • If a string ENDS with a particular set of characters, use $.
    • So if a string ends with NA, use NA$.
mplus_compile(Mplus_file = models,
              display = c("dataset", "dataset_title", "paramHeader", "param", "est"),
              parameter = "NA$")
#> # A tibble: 54 x 5
#>    dataset dataset_title paramHeader param  est  
#>      <int> <chr>         <chr>       <chr>  <chr>
#>  1       1 1_naAR_CESD   NAVAR.|     NA     0.92 
#>  2       1 1_naAR_CESD   Z.ON        NAONNA 0.35 
#>  3       1 1_naAR_CESD   Z.ON        NA     0.42 
#>  4       1 1_naAR_CESD   NA.WITH     NAONNA 0.22 
#>  5       1 1_naAR_CESD   Means       NA     2.26 
#>  6       1 1_naAR_CESD   Means       NAONNA 1.08 
#>  7       1 1_naAR_CESD   Variances   NA     1.00 
#>  8       1 1_naAR_CESD   Variances   NAONNA 1.00 
#>  9       1 1_naAR_CESD   R2          NA     0.08 
#> 10       2 2_naAR_CESD   NAVAR.|     NA     0.88 
#> # ... with 44 more rows

You can see that the ‘param’ column in the table above no longer contains NAVAR, as this string doesn’t end in NA. If you want to specify just “NA” and not “NAONNA”, use both ^ and $. This means the phrase must start and end with NA, and cannot contain anything else in the middle.

mplus_compile(Mplus_file = models,
              display = c("dataset", "dataset_title", "paramHeader", "param", "est"),
              parameter = "^NA$")
#> # A tibble: 30 x 5
#>    dataset dataset_title paramHeader param est  
#>      <int> <chr>         <chr>       <chr> <chr>
#>  1       1 1_naAR_CESD   NAVAR.|     NA    0.92 
#>  2       1 1_naAR_CESD   Z.ON        NA    0.42 
#>  3       1 1_naAR_CESD   Means       NA    2.26 
#>  4       1 1_naAR_CESD   Variances   NA    1.00 
#>  5       1 1_naAR_CESD   R2          NA    0.08 
#>  6       2 2_naAR_CESD   NAVAR.|     NA    0.88 
#>  7       2 2_naAR_CESD   Z.ON        NA    0.39 
#>  8       2 2_naAR_CESD   Means       NA    1.75 
#>  9       2 2_naAR_CESD   Variances   NA    1.00 
#> 10       2 2_naAR_CESD   R2          NA    0.12 
#> # ... with 20 more rows

Other aspects of the tibble that can be adjusted is the rounding, whether standardized output are displayed, whether non-converged models are automatically removed, and whether the content in the ‘define’ component of the output is displayed. More info on these arguments can be found here.

Example 3: APA-style Table Options

There are also several display options for the APA-style tables.

Horizontal vs Vertical Output

By default all output is displayed (type = "general") vertically (orientation = "vertical") but output can also be displayed horizontally:

# To start, we prepare a simpler dataset containing only the 
# parameter header Z.ON and parameters containing NA. 
tidy_z_on <- mplus_compile(Mplus_file = models,
              param_header = "Z.ON", 
              param = "^NA",
              display = "minimal")

# Displaying the results vertically (the default)
mplus_apa_table(data = tidy_z_on,
                orientation = "vertical")
dataset dataset_title paramHeader param value
1 1 1_naAR_CESD Z.ON NAONNA 0.35
[0.06, 0.63]
2 1 1_naAR_CESD Z.ON NAVAR 0.14
[-0.08, 0.36]
3 1 1_naAR_CESD Z.ON NA 0.42
[0.21, 0.63]
4 2 2_naAR_CESD Z.ON NAONNA -0.07
[-0.34, 0.20]
5 2 2_naAR_CESD Z.ON NAVAR 0.05
[-0.20, 0.29]
6 2 2_naAR_CESD Z.ON NA 0.39
[0.12, 0.65]
7 3 3_naAR_QIDS Z.ON NAONNA 0.05
[-0.11, 0.21]
8 3 3_naAR_QIDS Z.ON NAVAR 0.15
[0.00, 0.28]
9 3 3_naAR_QIDS Z.ON NA 0.70
[0.58, 0.81]
10 4 1_naAR_SWL Z.ON NAONNA -0.15
[-0.47, 0.17]
11 4 1_naAR_SWL Z.ON NAVAR -0.14
[-0.38, 0.09]
12 4 1_naAR_SWL Z.ON NA -0.16
[-0.39, 0.06]
13 5 2_naAR_SWL Z.ON NAONNA 0.18
[-0.09, 0.45]
14 5 2_naAR_SWL Z.ON NAVAR -0.09
[-0.32, 0.16]
15 5 2_naAR_SWL Z.ON NA -0.39
[-0.65, -0.12]
16 6 3_naAR_SWL Z.ON NAONNA 0.06
[-0.15, 0.26]
17 6 3_naAR_SWL Z.ON NAVAR -0.18
[-0.36, -0.00]
18 6 3_naAR_SWL Z.ON NA -0.54
[-0.70, -0.37]
# Displaying the results horizontally
mplus_apa_table(data = tidy_z_on,
                orientation = "horizontal")
dataset dataset_title paramheader: Z.ON
param: NAONNA
paramheader: Z.ON
param: NAVAR
paramheader: Z.ON
param: NA
1 1 1_naAR_CESD 0.35
[0.06, 0.63]
0.14
[-0.08, 0.36]
0.42
[0.21, 0.63]
2 2 2_naAR_CESD -0.07
[-0.34, 0.20]
0.05
[-0.20, 0.29]
0.39
[0.12, 0.65]
3 3 3_naAR_QIDS 0.05
[-0.11, 0.21]
0.15
[0.00, 0.28]
0.70
[0.58, 0.81]
4 4 1_naAR_SWL -0.15
[-0.47, 0.17]
-0.14
[-0.38, 0.09]
-0.16
[-0.39, 0.06]
5 5 2_naAR_SWL 0.18
[-0.09, 0.45]
-0.09
[-0.32, 0.16]
-0.39
[-0.65, -0.12]
6 6 3_naAR_SWL 0.06
[-0.15, 0.26]
-0.18
[-0.36, -0.00]
-0.54
[-0.70, -0.37]

Correlations Tables

You can specify a correlations table using type = "correlation", and specify the number of tables to display using n_tables.

You can specify one table (e.g. table 4, n_tables = 4), a range of tables (e.g., tables 3 through 7, n_tables = 3:7), or a specific subset of tables (e.g., tables 1 through 3 and table 5, n_tables = c(1:3, 5)).

# First prepare your correlations table by ensuring only values in param_header "WITH" are shown
tidy_cor <- mplus_compile(Mplus_file = models, 
                            standardized = TRUE,  
                            rounding = 3,
                            param_header = "WITH",
                            display = "minimal")


# Save your html table as an object
table <- mplus_apa_table(data = tidy_cor, 
                type = "correlation",
                n_tables = c(1:2, 5))

At this point you can show the correlations table/s in R like this:

htmltools::HTML(table)
1_naAR_CESD
NA NAONNA NAVAR
NA - 0.222
[-0.099, 0.537]
-0.231
[-0.447, 0.000]
NAONNA - -0.128
[-0.465, 0.209]
NAVAR -
2_naAR_CESD
NA NAONNA NAVAR
NA - 0.393
[0.165, 0.601]
0.517
[0.350, 0.665]
NAONNA - -0.044
[-0.293, 0.209]
NAVAR -
2_paAR_CESD
PA PAONPA PAVAR
PA - -0.054
[-0.304, 0.203]
0.043
[-0.174, 0.257]
PAONPA - -0.217
[-0.456, 0.039]
PAVAR -

Or you can save the html table/s like this:


write(table, file = "table.html", sep = "\n")

Multilevel Reliability

For this example we will be loading in another dataset which contains alpha coefficients.

Step 1: rename data files
The data files originally look like this:

dir <- "reliability"
list.files(dir)
#>  [1] "ESM_S1_FEEL NA (3item) ML-alpha.inp"    
#>  [2] "ESM_S1_FEEL NA (3item) ML-alpha.out"    
#>  [3] "ESM_S1_FEEL reap (2item) ML-alpha.inp"  
#>  [4] "ESM_S1_FEEL reap (2item) ML-alpha.out"  
#>  [5] "ESM_S2_LELODEF NA (5item) ML-alpha.inp" 
#>  [6] "ESM_S2_LELODEF NA (5item) ML-alpha.out" 
#>  [7] "ESM_S2_LELODEF rum (2item) ML-alpha.inp"
#>  [8] "ESM_S2_LELODEF rum (2item) ML-alpha.out"
#>  [9] "ESM_S3_YLL NA (4item) ML-alpha.inp"     
#> [10] "ESM_S3_YLL NA (4item) ML-alpha.out"     
#> [11] "ESM_S3_YLL rum (3item) ML-alpha.inp"    
#> [12] "ESM_S3_YLL rum (3item) ML-alpha.out"    
#> [13] "ESM_S4_MBP NA (4item) ML-alpha.inp"     
#> [14] "ESM_S4_MBP NA (4item) ML-alpha.out"     
#> [15] "ESM_S5_BJ NA (7item) ML-alpha.inp"      
#> [16] "ESM_S5_BJ NA (7item) ML-alpha.out"      
#> [17] "ESM_S5_BJ rum (2item) ML-alpha.inp"     
#> [18] "ESM_S5_BJ rum (2item) ML-alpha.out"

They contain prohibited characters such as brackets, spaces, and dashes, so these files will need to be renamed.


fix_file_names(dir = dir)

The files are now ready to be read in.

list.files(dir)
#>  [1] "ESM_S1_FEEL_NA__3item__ML_alpha.inp"    
#>  [2] "ESM_S1_FEEL_NA__3item__ML_alpha.out"    
#>  [3] "ESM_S1_FEEL_reap__2item__ML_alpha.inp"  
#>  [4] "ESM_S1_FEEL_reap__2item__ML_alpha.out"  
#>  [5] "ESM_S2_LELODEF_NA__5item__ML_alpha.inp" 
#>  [6] "ESM_S2_LELODEF_NA__5item__ML_alpha.out" 
#>  [7] "ESM_S2_LELODEF_rum__2item__ML_alpha.inp"
#>  [8] "ESM_S2_LELODEF_rum__2item__ML_alpha.out"
#>  [9] "ESM_S3_YLL_NA__4item__ML_alpha.inp"     
#> [10] "ESM_S3_YLL_NA__4item__ML_alpha.out"     
#> [11] "ESM_S3_YLL_rum__3item__ML_alpha.inp"    
#> [12] "ESM_S3_YLL_rum__3item__ML_alpha.out"    
#> [13] "ESM_S4_MBP_NA__4item__ML_alpha.inp"     
#> [14] "ESM_S4_MBP_NA__4item__ML_alpha.out"     
#> [15] "ESM_S5_BJ_NA__7item__ML_alpha.inp"      
#> [16] "ESM_S5_BJ_NA__7item__ML_alpha.out"      
#> [17] "ESM_S5_BJ_rum__2item__ML_alpha.inp"     
#> [18] "ESM_S5_BJ_rum__2item__ML_alpha.out"

Step 2: Read in the data
Remember to set recursive = TRUE regardless of whether there are subfolders, and set target to the directory your files are stored in.

reliability_data <- readModels(target = dir, recursive = TRUE)
#> Reading model:  reliability_fixed/ESM_S1_FEEL_NA__3item__ML_alpha.out 
#> Reading model:  reliability_fixed/ESM_S1_FEEL_reap__2item__ML_alpha.out 
#> Reading model:  reliability_fixed/ESM_S2_LELODEF_NA__5item__ML_alpha.out 
#> Reading model:  reliability_fixed/ESM_S2_LELODEF_rum__2item__ML_alpha.out 
#> Reading model:  reliability_fixed/ESM_S3_YLL_NA__4item__ML_alpha.out 
#> Reading model:  reliability_fixed/ESM_S3_YLL_rum__3item__ML_alpha.out 
#> Reading model:  reliability_fixed/ESM_S4_MBP_NA__4item__ML_alpha.out 
#> Reading model:  reliability_fixed/ESM_S5_BJ_NA__7item__ML_alpha.out 
#> Reading model:  reliability_fixed/ESM_S5_BJ_rum__2item__ML_alpha.out

Step 3: Create a tidy dataset

For a multilevel reliability table we only want the parameters than contain ALPHA, and we’re only interested in the estimates and confidence intervals so we’ll set display = minimal. The alpha coefficients are unstandardized, so we need to set standardized = FALSE.

reliability_tidy <- mplus_compile(Mplus_file = reliability_data,
                        standardized = FALSE,
                        parameter = "ALPHA",
                        display = "minimal")

reliability_tidy
#> # A tibble: 18 x 7
#>    dataset dataset_title      paramHeader    param est   lower_2.5ci upper_2.5ci
#>      <int> <chr>              <chr>          <chr> <chr> <chr>       <chr>      
#>  1       1 ESM_S1_FEEL_NA__3~ New.Additiona~ ALPH~ 0.62  0.61        0.63       
#>  2       1 ESM_S1_FEEL_NA__3~ New.Additiona~ ALPH~ 0.89  0.85        0.92       
#>  3       2 ESM_S1_FEEL_reap_~ New.Additiona~ ALPH~ 0.59  0.58        0.60       
#>  4       2 ESM_S1_FEEL_reap_~ New.Additiona~ ALPH~ 0.99  0.98        0.99       
#>  5       3 ESM_S2_LELODEF_NA~ New.Additiona~ ALPH~ 0.72  0.72        0.73       
#>  6       3 ESM_S2_LELODEF_NA~ New.Additiona~ ALPH~ 0.93  0.91        0.95       
#>  7       4 ESM_S2_LELODEF_ru~ New.Additiona~ ALPH~ 0.40  0.38        0.42       
#>  8       4 ESM_S2_LELODEF_ru~ New.Additiona~ ALPH~ 0.81  0.75        0.86       
#>  9       5 ESM_S3_YLL_NA__4i~ New.Additiona~ ALPH~ 0.74  0.73        0.76       
#> 10       5 ESM_S3_YLL_NA__4i~ New.Additiona~ ALPH~ 0.95  0.92        0.97       
#> 11       6 ESM_S3_YLL_rum__3~ New.Additiona~ ALPH~ 0.74  0.73        0.76       
#> 12       6 ESM_S3_YLL_rum__3~ New.Additiona~ ALPH~ 0.98  0.97        0.99       
#> 13       7 ESM_S4_MBP_NA__4i~ New.Additiona~ ALPH~ 0.74  0.73        0.76       
#> 14       7 ESM_S4_MBP_NA__4i~ New.Additiona~ ALPH~ 0.92  0.89        0.94       
#> 15       8 ESM_S5_BJ_NA__7it~ New.Additiona~ ALPH~ 0.74  0.73        0.75       
#> 16       8 ESM_S5_BJ_NA__7it~ New.Additiona~ ALPH~ 0.94  0.92        0.96       
#> 17       9 ESM_S5_BJ_rum__2i~ New.Additiona~ ALPH~ 0.68  0.67        0.70       
#> 18       9 ESM_S5_BJ_rum__2i~ New.Additiona~ ALPH~ 0.85  0.78        0.90

Step 4: Apply APA formatting

In this case we are only interested in standard formatting, but we want the results to be displayed horizontally by param (ALPHAW and ALPHAB) so we set orientation = "horizontal".

reliability_table <- mplus_apa_table(data = reliability_tidy,
                                     type = "general",
                                     orientation = "horizontal")

htmltools::HTML(reliability_table)
dataset dataset_title paramheader: New.Additional.Parameters
param: ALPHAW
paramheader: New.Additional.Parameters
param: ALPHAB
1 1 ESM_S1_FEEL_NA__3item__ML_alpha 0.62
[0.61, 0.63]
0.89
[0.85, 0.92]
2 2 ESM_S1_FEEL_reap__2item__ML_alpha 0.59
[0.58, 0.60]
0.99
[0.98, 0.99]
3 3 ESM_S2_LELODEF_NA__5item__ML_alpha 0.72
[0.72, 0.73]
0.93
[0.91, 0.95]
4 4 ESM_S2_LELODEF_rum__2item__ML_alpha 0.40
[0.38, 0.42]
0.81
[0.75, 0.86]
5 5 ESM_S3_YLL_NA__4item__ML_alpha 0.74
[0.73, 0.76]
0.95
[0.92, 0.97]
6 6 ESM_S3_YLL_rum__3item__ML_alpha 0.74
[0.73, 0.76]
0.98
[0.97, 0.99]
7 7 ESM_S4_MBP_NA__4item__ML_alpha 0.74
[0.73, 0.76]
0.92
[0.89, 0.94]
8 8 ESM_S5_BJ_NA__7item__ML_alpha 0.74
[0.73, 0.75]
0.94
[0.92, 0.96]
9 9 ESM_S5_BJ_rum__2item__ML_alpha 0.68
[0.67, 0.70]
0.85
[0.78, 0.90]

Step 5: Save your table

write(reliability_table, file = "reliability_table.html", sep = "\n")