R中CCA的拟合优度 [英] Goodness of fit in CCA in R
问题描述
以下是数据集
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
对于psych和acad这些数据集,我想进行规范相关分析,并获得以下规范相关系数和规范载荷:
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)
我想知道R中是否有一个包或函数可以自动计算规范维/变量的显着性,还需要测试整体模型以进行规范相关性分析并总结如下:
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:
推荐答案
使用R中的CCP包,我们可以计算规范相关分析的统计显着性.
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]
##计算规范相关性("cancor"是统计数据包的一部分):
## Calculate canonical correlations ("cancor" is part of the stats-package):
rho <- cancor(psych,acad)$cor
##使用不同测试统计量的F逼近来计算p值:
## 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")
##考虑3、2或1个规范相关,绘制威尔克斯Lambda的F逼近:
## 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")
这篇关于R中CCA的拟合优度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!