问题
The following are the datasets
mm <- read.csv("https://stats.idre.ucla.edu/stat/data/mmreg.csv")
colnames(mm) <- c("Control", "Concept", "Motivation", "Read", "Write", "Math",
"Science", "Sex")
psych <- mm[, 1:3] # dataset A
acad <- mm[, 4:8] # dataset B
For these datasets psych and acad,I wanted to do the canonical correlation analysis and obtained the canonical correlation coefficients and canonical loadings as follows:
require(CCA)
cc1 <- cc(psych, acad)
I would like to know if there is a package or function in R to automatically compute the significance of the canonical dimensions/variates.And also something to test the overall model fit for canonical correlation analysis and summarize as follows:
回答1:
using package CCP in R, we can calculate the statistical significance of the canonical correlation analysis.
library(CCP)
## Define number of observations, number of dependent variables, number of independent variables.
N = dim(psych)[1]
p = dim(psych)[2]
q = dim(acad)[2]
## Calculate canonical correlations ("cancor" is part of the stats-package):
rho <- cancor(psych,acad)$cor
## Calculate p-values using the F-approximations of different test statistics:
p.asym(rho, N, p, q, tstat = "Wilks")
p.asym(rho, N, p, q, tstat = "Hotelling")
p.asym(rho, N, p, q, tstat = "Pillai")
p.asym(rho, N, p, q, tstat = "Roy")
## Plot the F-approximation for Wilks’ Lambda, considering 3, 2, or 1 canonical correlation(s):
res1 <- p.asym(rho, N, p, q)
plt.asym(res1,rhostart=1)
plt.asym(res1,rhostart=2)
plt.asym(res1,rhostart=3)
Going a step further the permutation tests were then calculated as:
p.perm(psych, acad, nboot = 999, rhostart = 1, type = "Wilks")
来源:https://stackoverflow.com/questions/21672302/goodness-of-fit-in-cca-in-r