cr, cr.brief
Correlation coefficient with hypothesis test and confidence interval for two variables, or the correlation matrix for a data frame with more than two variables. The computed coefficient(s) are the standard Pearson's product-moment correlation. For the default missing data technique of pairwise deletion, an analysis of missing data for each computed correlation coefficient is provided, and also a statistical summary of the missing data across all cells.
Correlation(x, y, dframe=mydata,
miss=c("pairwise", "listwise", "everything"),
show.n=NULL, brief=FALSE, n.cat=getOption("n.cat"), digits.d=NULL,
colors=c("blue", "gray", "rose", "green", "gold", "red"),
heat.map=TRUE, main=NULL, bottom=3, right=3,
pdf.file=NULL, pdf.width=5, pdf.height=5, ...)cr.brief(..., brief=TRUE)
cr(...)
mydata
.FALSE
, then the sample covariance and number of non-missing
and missing observations are displayed.TRUE
and a matrix analyzed, displays a heat map of the
matrix of correlation coefficients.main=""
to turn off.cor
, cor.test
, cov
.In place of two variables x and y, x can be a complete data frame. All the variables in the data frame must be numeric. If not, then an appropriate error message is displayed. Given such a data frame, the correlation matrix of all the variables in the data frame is displayed.
The computed coefficient(s) are the standard Pearson's product-moment correlation. Use the standard R functions cor
and cor.test
to obtain Spearman and Kendall correlation coefficients.
For treating missing data, the default is pairwise
, which means that an observation is deleted only for the computation of a specific correlation coefficient if one or both variables are missing the value for the relevant variable(s). For listwise
deletion, the entire observation is deleted from the analysis if any of its data values are missing. For the more radical everything
option, any missing data values for a variable result in all correlations for that variable reported as missing.
Text output to the console provides feedback, and the correlation matrix itself is written to a matrix called mycor
, stored in the user's workspace. This matrix is ready for input into any of the lessR
functions that analyze correlational data, including confirmatory factor analysis by corCFA
and also exploratory factor analysis, either the standard R function factanal
or the lessR
function corEFA
.
cor.test
, cov
.# data
n <- 12
f <- sample(c("Group1","Group2"), size=n, replace=TRUE)
x <- round(rnorm(n=n, mean=50, sd=10), 2)
y <- round(rnorm(n=n, mean=50, sd=10), 2)
z <- round(rnorm(n=n, mean=50, sd=10), 2)
mydata <- data.frame(f,x,y,z)
rm(f); rm(x); rm(y); rm(z)
# correlation and covariance
Correlation(x,y)
# short name
cr(x,y)
# brief form of output
cr.brief(x,y)
# correlation matrix
# first remove the categorical variable f from mydata
mydata <- subset(mydata, select=c(x:z))
# now analyze remaining variables x, y and z
Correlation(mydata)
# analysis with data not from data frame mydata
data(attitude)
Correlation(rating, learning, dframe=attitude)
Run the code above in your browser using DataLab