Makes use of functions adapted from the lavaan package to find FIML covariance/correlation matrices. FIML can be much slower than the normal pairwise deletion option of cor, but provides slightly more precise estimates.

corFiml(x, covar = FALSE,show=FALSE)

Arguments

x

A data.frame or data matrix

covar

By default, just return the correlation matrix. If covar is TRUE, return a list containing the covariance matrix and the ML fit function.

show

If show=TRUE, then just show the patterns of missingness, but don't do the FIML. Useful for understanding the process of fiml.

Details

In the presence of missing data, Full Information Maximum Likelihood (FIML) is an alternative to simply using the pairwise correlations. The implementation in the lavaan package for structural equation modeling has been adapted for the simpler case of just finding the correlations or covariances.

The pairwise solution for any pair of variables is insensitive to other variables included in the matrix. On the other hand, the ML solution depends upon the entire set of items being correlated. This will lead to slightly different solutions for different subsets of variables.

The basic FIML algorithm is to find the pairwise ML solution for covariances and means for every pattern of missingness and then to weight the solution by the size of every unique pattern of missingness.

Value

cor

The correlation matrix found using FIML

cov

The covariance matrix found using FIML

fx

The ML fit function

Author

Wiliam Revelle

Note

The functions used in lavaan are not exported and so have been copied (and simplified) to the psych package.

See also

To use the resulting correlations, see fa. To see the pairwise pattern of missingness, see count.pairwise.

Examples

rML <- corFiml(bfi[20:27])
rpw <- cor(bfi[20:27],use="pairwise") 
round(rML - rpw,3)
#>               N5     O1     O2     O3     O4     O5 gender education
#> N5         0.000  0.000 -0.001 -0.001  0.000 -0.001 -0.002     0.001
#> O1         0.000  0.000  0.001  0.000 -0.001  0.001  0.000     0.001
#> O2        -0.001  0.001  0.000  0.001  0.000 -0.002  0.000     0.001
#> O3        -0.001  0.000  0.001  0.000 -0.001  0.000 -0.002     0.001
#> O4         0.000 -0.001  0.000 -0.001  0.000  0.000  0.000     0.001
#> O5        -0.001  0.001 -0.002  0.000  0.000  0.000  0.000     0.001
#> gender    -0.002  0.000  0.000 -0.002  0.000  0.000  0.000     0.001
#> education  0.001  0.001  0.001  0.001  0.001  0.001  0.001     0.000
mp <- corFiml(bfi[20:27],show=TRUE)
mp
#>         N5    O1   O2    O3    O4    O5 gender education
#> 2489  TRUE  TRUE TRUE  TRUE  TRUE  TRUE   TRUE      TRUE
#> 214   TRUE  TRUE TRUE  TRUE  TRUE  TRUE   TRUE     FALSE
#> 22   FALSE  TRUE TRUE  TRUE  TRUE  TRUE   TRUE      TRUE
#> 19    TRUE  TRUE TRUE FALSE  TRUE  TRUE   TRUE      TRUE
#> 18    TRUE FALSE TRUE  TRUE  TRUE  TRUE   TRUE      TRUE
#> 13    TRUE  TRUE TRUE  TRUE  TRUE FALSE   TRUE      TRUE
#> 13    TRUE  TRUE TRUE  TRUE FALSE  TRUE   TRUE      TRUE
#> 3     TRUE  TRUE TRUE FALSE  TRUE  TRUE   TRUE     FALSE
#> 2    FALSE FALSE TRUE FALSE  TRUE FALSE   TRUE      TRUE
#> 2    FALSE FALSE TRUE FALSE  TRUE FALSE   TRUE     FALSE
#> 1     TRUE  TRUE TRUE  TRUE  TRUE FALSE   TRUE     FALSE
#> 1     TRUE  TRUE TRUE  TRUE FALSE  TRUE   TRUE     FALSE
#> 1    FALSE  TRUE TRUE  TRUE  TRUE  TRUE   TRUE     FALSE
#> 1    FALSE  TRUE TRUE FALSE  TRUE FALSE   TRUE      TRUE
#> 1    FALSE  TRUE TRUE FALSE  TRUE FALSE   TRUE     FALSE