orthpoly<-function(w,x=0:(length(w)-1),qstart=1) { # orthogonal polynomial values using weights w # w<-w/sum(w) n<-length(w) p<-matrix(0,nrow=n+1,ncol=n) A<-matrix(0,nrow=n,ncol=1) B<-matrix(0,nrow=n,ncol=1) q<-matrix(0,nrow=n,ncol=n) p[(-1)+2,]<-0 # p_{-1}=0 q[(0)+1,]<-qstart # q_{0}=1 (default) A[(0)+1]<-sqrt(sum(w*q[(0)+1,]^2)) p[(0)+2,]<-q[(0)+1,]/A[(0)+1] for (j in 1:(n-1)) { B[(j)+1]<-sum(x*w*q[(j-1)+1,]^2)/sum(w*q[(j-1)+1,]^2) q[(j)+1,]<-(x-B[(j)+1])*p[(j-1)+2,]-A[(j-1)+1]*p[(j-2)+2,] A[(j)+1]<-sqrt(sum(w*q[(j)+1,]^2)) p[(j)+2,]<-q[(j)+1,]/A[(j)+1] } return(p[((0)+2):((n-1)+2),]) } orthpoly(rep(1/6,6)) # [,1] [,2] [,3] [,4] [,5] [,6] #[1,] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 #[2,] -1.4638501 -0.8783101 -0.2927700 0.2927700 0.8783101 1.4638501 #[3,] 1.3363062 -0.2672612 -1.0690450 -1.0690450 -0.2672612 1.3363062 #[4,] -0.9128709 1.2780193 0.7302967 -0.7302967 -1.2780193 0.9128709 #[5,] 0.4629100 -1.3887301 0.9258201 0.9258201 -1.3887301 0.4629100 #[6,] -0.1543033 0.7715167 -1.5430335 1.5430335 -0.7715167 0.1543033 doit<-function(Nij,mult,SSeffects.max=4,SSeffects.min=1,rankscores=T,residualSS.pval=0.15,SS.pval=0.10) { t<-nrow(Nij) k<-ncol(Nij) ni<-apply(Nij,1,sum) nj<-apply(Nij,2,sum) n<-sum(ni) pj<-nj/n if (rankscores) xj<-cumsum(c(0,nj)[-(k+1)])+(nj+1)/2 else xj<-1:k G<-orthpoly(pj,xj) # tCri<-Nij%*%t(G[-1,])/sqrt(ni)*sqrt(mult) colnames(tCri)<-1:ncol(tCri) for (i in 1:ncol(tCri)) colnames(tCri)[i]<-paste(i,"-th order",sep="") colnames(tCri)[1:min(4,ncol(tCri))]<-c("Location","Dispersion","Skewness","Kurtosis")[1:min(4,ncol(tCri))] # SS<-apply(tCri^2,2,sum) df<-rep(t-1,k-1) #choose i so that no individual pvals