-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwoFactorTheSameGroupSize.R
92 lines (69 loc) · 1.58 KB
/
TwoFactorTheSameGroupSize.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
file<-read.csv("Propydevt.csv",sep=";", dec=",", header = TRUE);
newFile<-file[order(file$Ãð..Òÿæåñòü),]
sink("statistics2.txt", split=TRUE)
K<-length(newFile[newFile[[1]]==1,])
p1<-5; p2<-4 # p1 - levels of gruz, levels of Na-Li
for(i in 1:p1){
len<-length(newFile[newFile[[1]]==i,]$Na.Li)
print(K)
if (len < K) K<-len
}
K<-K%/%p2 # for similar count in each
vA<-p1-1
vB<-p2-1
vAB<-(p1-1)*(p2-1)
vE<-(p1-1)*(p2-1)
print(paste0("vA: ", vA))
print(paste0("vB: ", vB))
print(paste0("vAB: ", vAB))
print(paste0("vE: ", vE))
arr<- array(1, dim=c(p1,p2,K))
for(i in 1:p1){
for (k in 1:K) {
for(j in 1:p2) {
arr[i, j, k]<-newFile[newFile[[1]]==i,]$ÔÈÁÐ[[j]]
}
}
}
SSA<-0; SSB<-0; SSE<-0
n<-p1*p2
generalMean<-0
for(i in 1:p1){
for(j in 1:p2){
generalMean<-generalMean + arr[i, j, K]
}
}
generalMean<-generalMean/n
meanA<-list()
meanB<-list()
for(i in 1:p1){
meanA[[i]]<-mean(arr[i, , K])
}
for(i in 1:p2){
meanB[[i]]<-mean(arr[ , i, K])
}
for(i in 1:p1){
SSA<-SSA + (meanA[[i]] - generalMean)^2
}
SSA<-SSA*p2
for(i in 1:p2){
SSB<-SSB + (meanB[[i]] - generalMean)^2
}
SSB<-SSB*p1
print(paste0("SSA: ", SSA))
print(paste0("SSB: ", SSB))
SSE<-0
for(i in 1:p1){
for(j in 1:p2){
SSE<-SSE + (arr[i, j, K] - meanA[[i]] - meanB[[j]] + generalMean)^2
}
}
print(paste0("SSE: ", SSE))
FstatA<-(SSA/ vA) / (SSE/ vE)
FstatB<-(SSB/ vA) / (SSA/ vE)
fACriterium<-pf(FstatA, vA, vE);
alphaA<-1-fACriterium;
fBCriterium<-pf(FstatB, vB, vE);
alphaB<-1-fBCriterium;
print(paste0("alphaA: ", alphaA))
print(paste0("alphaB: ", alphaB))