# Prediction Problems library(MASS) zlrs = file.choose() source(zlrs) # Connectedness problem for group work (1,1,1) (1,1,3) (1,2,1) (1,3,2) (1,3,5) (2,1,3) (2,1,4) (2,2,1) (2,2,2) (2,2,5) (2,3,1) (3,1,4) (3,1,5) (3,3,1) (3,3,3) (4,1,2) (4,2,2) (4,3,4) (1,1,1) (1,1,3) (1,2,1) (2,1,3) (2,2,1) # 1)Determine the number of disconnected groups of the # above filled subclasses. # 2)Which subclasses (minimum number) are needed in # order to connect all of these groups? # small prediction problem y = matrix(data=c(128,150,90,110,120),ncol=1) X = matrix(data=c(1,1,1,1,1),ncol=1) herds = c(1,1,2,2,2) sires = c(1,2,1,2,3) Zh = desgn(herds,0) Zs = desgn(sires,0) Z = cbind(Zh,Zs) Gh = id(2)*(1/6) Gs = id(3)*(1/15) G = block(Gh,Gs) dd = c(5,4,5,20,2) RI=diag(dd) # Pigs in litters Litter 1 1, 2, 3, 4, 5 13, 10, 9, 16, 8 2 6, 7, 8, 9 15, 12, 7, 18 3 10, 11, 12, 13, 14, 15 20, 11, 9, 17, 10, 14 ---------------------------------- y = mu + litter + pig + e e = 10 l = 3 p lits = c(1,1,1,1,1,2,2,2,2,3,3,3,3,3,3) pigs = c(1:15) oval = rep(1,length(lits)) y = matrix(c(13,10,9,16,8,15,12,7,18,20,11,9,17,10,14),ncol=1) Xm = desgn(oval,3) Zl = desgn(lits,0) Zp = desgn(pigs,0) Gl = id(3)*10 G2 = id(15)*3 GI = block(Gl,G2) Z= cbind(Zl,Zp) RI=id(15) att1=MME(Xm,Z,GI,RI,y) litsol=att1$SOLNS[c(2:4), ] gL1 = jd(5,5)*0.5 + id(5)*0.5 gL1 gL2 = jd(4,4)*0.5 + id(4)*0.5 gL3 = jd(6,6)*0.5 + id(6)*0.5 G2 = block(gL1,gL2,gL3) dim(G2) # FORGOT THIS PART !!!!!! G2I = solve(G2)*3 GI=block(Gl,G2I) att2=MME(Xm,Z,GI,RI,y) p2nd = att2$SOLNS[c(5:19), ] kb=order(-p2nd) kb l1st=att1$SOLNS[c(2:4), ] l2nd=att2$SOLNS[c(2:4), ] cbind(l1st,l2nd) cbind(pall,p2nd) sst = sum(y*y) ssr = att2$SSR vres = (sst - ssr)/(15-1) vpe = att2$VPE sep = sqrt(vpe) sol=att2$SOLNS cbind(sol,sep,rti) rti = (1 - vpe*3) PL = sol[c(2:19), ] GEN= Z%*%PL GEN ka = order(-GEN) ka # Evaluation of pigs = lits + pigs solutions, SEP of these # pigs unrelated between litters # put in full-sib relationships - compare models #Homework Problem, plant heights y = matrix(data=c(25.3,17.8,20.1,26.1,19.2,24.6,23.7,24.5,26.0,28.4,22.9,25.8), ncol=1) dd = c(40,39,37,35,40,40,33,38,40,30,28,34) RI=diag(dd) FB=c(1,1,1,2,2,2,3,3,3,4,4,4) X =desgn(FB,0) LL=c(1,2,3,1,2,3,1,2,3,1,2,3) Z = desgn(LL,0) qq = c(10,10,10) GI=diag(qq) dand=data.frame(y,dd,FB,LL) dand