-
Notifications
You must be signed in to change notification settings - Fork 0
/
zad3.R
99 lines (90 loc) · 1.87 KB
/
zad3.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
87
88
89
90
91
92
93
94
95
96
97
98
99
set.seed(10)
macierz_genotypow = cbind(X,Y,Z) # 3 zlaczone chromosomy
k = 500
alfa = 0.05
powt = 100
osobniki = length(macierz_genotypow[,1]) # liczba osobnikow = 500
markery = length(X[1,]) # liczba markerow = 150
cechy = matrix(rnorm(osobniki*k),osobniki,k)
zliczA = 0
zliczB = 0
zliczC = 0
zliczD = 0
ksiZ = matrix(0, markery, k)
for (indeks in 1:k) {
cecha = cechy[,indeks]
pwar = rep(0,markery)
stat = rep(0,markery)
ST = matrix(0, powt, markery)
for (i in 1:markery){
gr1 = (Z[,i] == 0) * cecha
gr1 = gr1[gr1 != 0]
gr2 = (Z[,i] == 1) * cecha
gr2 = gr2[gr2 != 0]
pwar[i] = t.test(gr1, gr2, var.equal = TRUE)$p.value
stat[i] = t.test(gr1, gr2, var.equal = TRUE)$statistic
ksiZ[i,indeks] = abs(mean(gr2) - mean(gr1))
#ST[1,i] = stat[i]
#cem = matrix(sample(cecha), powt-1, osobniki)
#for (jj in 2:powt){
#ce = cem[(jj-1),]
#gru1 = (X[,i] == 0) * ce
#gru1 = gru1[gru1 != 0]
#gru2 = (X[,i] == 1) * ce
#gru2 = gru2[gru2 != 0]
#ST[jj,i] = abs(t.test(gru1, gru2, var.equal = TRUE)$statistic)
#}
}
#maxD = apply(ST, 2, max)
#critical_value2 = kwantyl(alfa, maxD)
if (length(pwar[(pwar<alfa) == TRUE]) != 0){
zliczA = zliczA + 1
}
if (length(pwar[(pwar<alfa/markery) == TRUE]) != 0){
zliczB = zliczB + 1
}
if (length(stat[(abs(stat)>critical_value3) == TRUE]) != 0){
zliczC = zliczC + 1
}
#if (length(stat[(abs(stat)>critical_value2) == TRUE]) != 0){
# zliczD = zliczD + 1
#}
}
pA = zliczA/k # 0.856
pB = zliczB/k # 0.008
pC = zliczC/k # 0.112
pD = zliczD/k #
# Y
# wyniki
# > pA
#[1] 0.506
#> pB
#1] 0.008
#> pC
#[1] 0.044
#> pD
#[1] 0.008 dla 100 permutacji
# X
#> pA
#[1] 0.46
#> pB
#[1] 0.012
#> pC
#[1] 0.044
#> pD
#[1] 0.02 dla 100 permutacji
# Z
# wyniki
# > pA
#[1] 0.472
#> pB
#[1] 0.008
#> pC
#[1] 0.048
#> pD
#[1] 0.012 dla 100 permutacji
# wyniki
pA
pB
pC
pD