Goodness of fit in CCA in R

99封情书 提交于 2019-12-10 21:07:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!