-
Notifications
You must be signed in to change notification settings - Fork 5
/
EX4
50 lines (31 loc) · 3.63 KB
/
EX4
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
Grafické znázornění mnohorozměrných dat a metoda hlavních komponent
1/ najděte vhodná mnohorozměrná data (v R knihovna datasets)
2/ data stručně popište a nakreslete
3/ zkuste použít a okomentovat metodu hlavních komponent
4/ pro zvolené dvě proměnné vypočítejte a nakreslete konfidenční intervaly pro střední hodnoty (i s Bonferroniho korekcí)
příklad na různé konfidenční oblasti pro dvourozměrná data:
#x1=log(fire2[,2])
#x2=log(fire2[,3])
x1=c(-0.151869908095343, 2.1729379362227, 2.06319702990122, 1.44070440035719, 0.832565416539469, 1.02133369180112, -0.282667922072004, 1.43311485752628, -0.183041240164348, 1.05805391067521, 0.00756242575638306, -0.0143208049769537, -2.43821285368876, 3.11891913127979, -0.651838274425697, 2.03654119724369, 3.1230482698691, 1.46379722362848, 1.99648346677704, 0.6033965121616, -0.335582952436329, 0.396073363515343, -0.115347928183382, 1.56579374559474, 3.16728040514282, 1.48077691661839, -3.23055872566714, 0.726282154965431, 2.3527772614342, 2.32598951670404, 1.06072970305646, -2.91043032345356, 1.01791167350359, 0.830001413815273, 2.0950196899776, 1.07970182525882, 0.438445082002274, -0.00465313868332665, 0.951746409268609, 0.320302919268962, 1.10996458390899, -0.62633128934163, -0.930475366866112, 4.21167692411359, 0.261954589541165, 1.1827637831159, 0.346787087752014, 1.94389035438764)
x2=c(-0.557816297796901, 1.97905203874403, 1.35605661751231, 1.13939085119201, 0.375274216583945, 0.564121164622909, -1.49327815575451, 0.858101159445995, -3.75581893678905, 0.117246475307822, -0.74689394036297, -0.137646992958209, -3.23170894194719, 2.55702067370603, -0.665819746853043, 1.73258254205821, 2.82639502018033, 0.723727293073901, 1.8321250858595, 0.377154263333835, -0.933985769801637, -0.0514610317782855, -0.320551004504882, 1.10449350538478, 2.82937531690223, 1.37152454844479, -0.867681402416971, -0.136991309294651, 1.69381729033385, 1.83503209615478, 1.36458094784119, -0.86691349729316, 1.18697681967914, 0.326845484565851, 1.67491499538855, 0.607687316606455, -0.418341255780347, -0.755919425853972, 1.07405260177247, -0.291490955976557, 0.353982123767476, -0.821041967161292, -3.16406758837321, 3.65087940683705, -0.320552142763511, 1.14873903114438, -0.169534229181188, 1.83911375412359)
rownamesf2=c("Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "District of Columbia", "Florida", "Georgia", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Virgin Islands", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming")
plot(x=x1,y=x2,type="n")
text(x=x1,y=x2,labels=rownamesf2)
points(x=mean(x1),y=mean(x2),col="red",pch=7,cex=3)
## marginalni t-testy
tt1=t.test(x1)$conf.int
tt2=t.test(x2)$conf.int
lines(x=c(tt1[1],tt1[1],tt1[2],tt1[2],tt1[1]), y=c(tt2[1],tt2[2],tt2[2],tt2[1],tt2[1]))
## elipsa
S=var(cbind(x1,x2))
ev=eigen(S)
S12=ev$vectors%*%diag(1/sqrt(ev$values))%*%t(ev$vectors)
n=nrow(fire2)
m1=mean(x1)
m2=mean(x2)
mriz=seq(-0.5,1.5,by=0.005)
contour(mriz,mriz,outer(mriz,mriz,function(x,y){n*apply((cbind(x-m1,y-m2)%*%S12)^2,1,sum)<=qchisq(0.95,2)}),add=TRUE,col="red",drawlabels=FALSE)
## bonferroni
tt1b=t.test(x1,conf.level=0.975)$conf.int
tt2b=t.test(x2,conf.level=0.975)$conf.int
lines(x=c(tt1b[1],tt1b[1],tt1b[2],tt1b[2],tt1b[1]), y=c(tt2b[1],tt2b[2],tt2b[2],tt2b[1],tt2b[1]),col="blue")