set.seed(11111)
T=20;p1=20;p2=20;k1=3;k2=3
R=matrix(runif(p1*k1,min=-1,max=1),p1,k1)
C=matrix(runif(p2*k2,min=-1,max=1),p2,k2)
X=array(0,c(T,p1,p2))
Y=X;E=Y
F=array(0,c(T,k1,k2))
for(t in 1:T){
F[t,,]=matrix(rnorm(k1*k2),k1,k2)
E[t,,]=matrix(rnorm(p1*p2),p1,p2)
Y[t,,]=R%*%F[t,,]%*%t(C)
}
X=Y+E
#Estimate the factor matrices and loadings by RMFA
fit1=MHFA(X, m1=3, m2=3, method="P")
Rhat1=fit1$R
Chat1=fit1$C
Fhat1=fit1$F
#Estimate the factor matrices and loadings by IHR
fit2=MHFA(X, W1=NULL, W2=NULL, 3, 3, "E")
Rhat2=fit2$R
Chat2=fit2$C
Fhat2=fit2$F
#Estimate the common component by RMFA
CC1=array(0,c(T,p1,p2))
for (t in 1:T){
CC1[t,,]=Rhat1%*%Fhat1[t,,]%*%t(Chat1)
}
CC1
#Estimate the common component by IHR
CC2=array(0,c(T,p1,p2))
for (t in 1:T){
CC2[t,,]=Rhat2%*%Fhat2[t,,]%*%t(Chat2)
}
CC2
Run the code above in your browser using DataLab