Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x1=matrix(c(2,12,4,10,3,8),byrow=T,nrow=3)
- x2=matrix(c(5,7,3,9,4,5),byrow=T,nrow=3)
- barx1=as.matrix(colMeans(x1))
- barx2=as.matrix(colMeans(x2))
- s1=2*cov(x1)
- s2=2*cov(x2)
- s.pooled=1/4 * (s1+s2)
- hat.a=barx1-barx2
- hat.y=t(hat.a)%*%solve(s.pooled)
- hat.y
- bar.y1=t(hat.a)%*%barx1
- bar.y2=t(hat.a)%*%barx2
- m=1/2*(bar.y1+bar.y2)
- p=c(0,0,0)
- clasifica=function(m){
- for (i in 1:dim(m)[1]){
- if(t(hat.a)%*%m[i,]>=22){
- p[i]=1
- } else{
- p[i]=2
- }
- }
- print(p)
- }
- clasifica(x1)
- clasifica(x2)
- #Primera observación de x1
- obs1x1=as.matrix(x1[1,])
- x1h1=x1[2:3,]
- barx1h1=as.matrix(colMeans(x1h1))
- s1h1=cov(x1h1)
- s.hpooled1h1=1/3 * (s1h1+s2)
- solve(s.hpooled1h1)
- t(obs1x1-barx1h1)%*%solve(s.hpooled1h1)%*%(obs1x1-barx1h1)
- t(obs1x1-barx2)%*%solve(s.hpooled1h1)%*%(obs1x1-barx2)
- #Segunda observación de x1
- obs1x2=as.matrix(x1[2,])
- x1h2=x1[c(1,3),]
- barx1h2=as.matrix(colMeans(x1h2))
- s1h2=cov(x1h2)
- s.hpooled1h2 = 1/3 * (s1h2+s2)
- solve(s.hpooled1h2)
- t(obs1x2-barx1h2)%*%solve(s.hpooled1h2)%*%(obs1x2-barx1h2)
- t(obs1x2-barx2)%*%solve(s.hpooled1h2)%*%(obs1x2-barx2)
- #Tercera observación de x1
- obs1x3=as.matrix(x1[3,])
- x1h3=x1[1:2,]
- barx1h3=as.matrix(colMeans(x1h3))
- s1h3=cov(x1h3)
- s.hpooled1h3 = 1/3 * (s1h3+s2)
- solve(s.hpooled1h3)
- t(obs1x3-barx1h3)%*%solve(s.hpooled1h3)%*%(obs1x3-barx1h3)
- t(obs1x3-barx2)%*%solve(s.hpooled1h3)%*%(obs1x3-barx2)
- #Primera observación de x2
- obs2x1=as.matrix(x2[1,])
- x2h1=x2[2:3,]
- barx2h1=as.matrix(colMeans(x2h1))
- s2h1=cov(x2h1)
- s.hpooled2h1 = 1/3 * (s1+s2h1)
- solve(s.hpooled2h1)
- t(obs2x1-barx1)%*%solve(s.hpooled2h1)%*%(obs2x1-barx1)
- t(obs2x1-barx2h1)%*%solve(s.hpooled2h1)%*%(obs2x1-barx2h1)
- #Segunda observación de x2
- obs2x2=as.matrix(x2[2,])
- x2h2=x2[c(1,3),]
- barx2h2=as.matrix(colMeans(x2h2))
- s2h2=cov(x2h2)
- s.hpooled2h2 = 1/3 * (s1+s2h2)
- solve(s.hpooled2h2)
- t(obs2x2-barx1)%*%solve(s.hpooled2h2)%*%(obs2x2-barx1)
- t(obs2x2-barx2h2)%*%solve(s.hpooled2h2)%*%(obs2x2-barx2h2)
- #Tercera observación de x3
- obs2x3=as.matrix(x2[3,])
- x2h3=x2[1:2,]
- barx2h3=as.matrix(colMeans(x2h3))
- s2h3=cov(x2h3)
- s.hpooled2h3 = 1/3 * (s1+s2h3)
- solve(s.hpooled2h3)
- t(obs2x3-barx1)%*%solve(s.hpooled2h3)%*%(obs2x3-barx1)
- t(obs2x3-barx2h3)%*%solve(s.hpooled2h3)%*%(obs2x3-barx2h3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement