psych.misc {psych}R Documentation

Miscellaneous helper functions for the psych package


This is a set of minor, if not trivial, helper functions. lowerCor finds the correlation of x variables and then prints them using lowerMat which is a trivial, but useful, function to round off and print the lower triangle of a matrix. reflect reflects the output of a factor analysis or principal components analysis so that one or more factors is reflected. (Requested by Alexander Weiss.) progressBar prints out ... as a calling routine (e.g., tetrachoric) works through a tedious calculation. shannon finds the Shannon index (H) of diversity or of information. test.all tests all the examples in a package. best.items sorts a factor matrix for absolute values and displays the expanded items names. fa.lookup returns sorted factor analysis output with item labels.


lowerMat(R, digits = 2)



A rectangular matrix or data frame (probably a correlation matrix)


A data matrix or data frame or a vector depending upon the function.


A data matrix or data frame or a vector


The object returned from either a factor analysis (fa) or a principal components analysis (principal)


round to digits


Should pairwise deletion be done, or one of the other options to cor


"pearson", "kendall", "spearman"


the current value of some looping variable


The maximum value the loop will achieve


what function is looping


The factor or components to be reversed keyed (by factor number)


Correct for the maximum possible information in this item


What is the base for the log function (default=2, e implies base = exp(1))


The name of a package to be activated and then have all the examples tested.


lowerCor prints out the lower off diagonal matrix rounded to digits with column names abbreviated to digits + 3 characters, but also returns the full and unrounded matrix. By default, it uses pairwise deletion of variables. It in turn calls

lowerMat which does the pretty printing.

It is important to remember to not call lowerCor when all you need is lowerMat!


tableF is fast alternative to the table function for creating two way tables of numeric variables. It does not have any of the elegant checks of the table function and thus is much faster. Used in the tetrachoric and polychoric functions to maximize speed.

The lower triangle of a matrix, rounded to digits with titles abbreviated to digits + 3 (lowerMat) or a series of dots (progressBar).

lowerCor prints the lower diagonal correlation matrix but returns (invisibly) the full correlation matrix found with the use and method parameters. The default values are for pairwise deletion of variables, and to print to 2 decimal places.

tableF (for tableFast) is a cut down version of table that does no error checking, nor returns pretty output, but is significantly faster than table. It will just work on two integer vectors. This is used in polychoric an tetrachoric for about a 50% speed improvement for large problems.

shannon finds Shannon's H index of information. Used for estimating the complexity or diversity of the distribution of responses in a vector or matrix.

H = -∑{p_i log(p_i) }

link{test.all} allows one to test all the examples in specified package. This allows us to make sure that those examples work when other packages are also loaded.

See Also

corr.test to find correlations, count the pairwise occurrences, and to give significance tests for each correlation. r.test for a number of tests of correlations, including tests of the difference between correlations. lowerUpper will display the differences between two matrices.


lb <- lowerCor(bfi[1:10])  #finds and prints the lower correlation matrix, 
  # returns the square matrix.
#fiml <- corFiml(bfi[1:10])     #FIML correlations require lavaan package
#lowerMat(fiml)  #to get pretty output
f3 <- fa(Thurstone,3)
f3r <- reflect(f3,2)  #reflect the second factor
#find the complexity of the response patterns of the iqitems.
#test.all('BinNor')  #Does the BinNor package work when we are using other packages
#to make this a latex table 
f2 <- fa(bfi[1:10],2)

[Package psych version 1.4.5 Index]
Part of the Personality Project      Take our Personality Test