# Implementations of the likelihood ratio test of Hardy-weinberg equilibrium for uncertain genotype in sibsips. # Qiong Li, Helene Massam and Xin Gao # June 27, 2013 # Arguments # num: a matrix of the numbers of sibships, with genptype configuration (AA), (Aa) and (aa) in rows and columns. # u: the probability of being incorrectly coded as a "a" allele when "A" is a true allele. # y: the probability of being incorrectly coded as a "A" allele when "a" is a true allele. # Examples # y <- 0.01 #epsilon1 # u <- 0.01 #epsilon2 # c <- c(2,3,0,1,22,10,0,8,54) # under HWE # c <- c(10,5,1,4,39,13,1,11,16) # without HWE # num <- matrix(c,nrow =3, ncol=3) # num[1,2] is the number of sibships with genotype (AA, Aa) # HWEtest.error(num, y, u) HWEtest.error <- function(num, y, u) { q <- matrix(0, nrow=6, ncol=6) # Penetrance matrix q[1,1] <- (1-y)^2*(1-y)^2 q[1,2] <- 1/4*(1-y)^2*(1-y)^2+2*1/4*(1-y)^2*u*(1-y)+1/4*u*(1-y)*u*(1-y) q[1,3] <- u*(1-y)*u*(1-y) q[1,4] <- 1/16*(1-y)^2*(1-y)^2+2*1/8*(1-y)^2*u*(1-y)+2*1/16*(1-y)^2*u^2+1/4*u*(1-y)*u*(1-y)+2*1/8*u*(1-y)*u^2+1/16*u^2*u^2 q[1,5] <- 1/4*u*(1-y)*u*(1-y)+2*1/4*u*(1-y)*u^2+1/4*u^2*u^2 q[1,6] <- u^2*u^2 q[2,1] <- (1-y)^2*2*y*(1-y) q[2,2] <- 1/4*(1-y)^2*2*y*(1-y)+1/4*(1-y)^2*(y*u+(1-y)*(1-u))+1/4*u*(1-y)*2*y*(1-y)+1/4*u*(1-y)*(y*u+(1-y)*(1-u)) q[2,3] <- u*(1-y)*(y*u+(1-y)*(1-u)) q[2,4] <- 1/16*(1-y)^2*2*y*(1-y)+1/8*(1-y)^2*(y*u+(1-y)*(1-u))+1/8*u*(1-y)*2*y*(1-y)+1/16*(1-y)^2*2*u*(1-u)+ 1/16*u^2*2*y*(1-y)+1/4*u*(1-y)*(y*u+(1-y)*(1-u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y*(1-y)*y^2 q[5,2] <- 1/4*2*y*(1-y)*y^2+1/4*2*y*(1-y)*y*(1-u)+1/4*(y*u+(1-y)*(1-u))*y^2+1/4*(y*u+(1-y)*(1-u))*y*(1-u) q[5,3] <- (y*u+(1-y)*(1-u))*y*(1-u) q[5,4] <- 1/16*2*y*(1-y)*y^2+1/8*2*y*(1-y)*y*(1-u)+1/8*(y*u+(1-y)*(1-u))*y^2+1/16*2*y*(1-y)*(1-u)^2+ 1/16*2*u*(1-u)*y^2+1/4*(y*u+(1-y)*(1-u))*y*(1-u)+1/8*(y*u+(1-y)*(1-u))*(1-u)^2+1/8*y*(1-u)*2*u*(1-u)+ 1/16*2*u*(1-u)*(1-u)^2 q[5,5] <- 1/4*(y*u+(1-y)*(1-u))*y*(1-u)+1/4*(y*u+(1-y)*(1-u))*(1-u)^2+1/4*y*(1-u)*2*u*(1-u)+ 1/4*2*u*(1-u)*(1-u)^2 q[5,6] <- 2*u*(1-u)*(1-u)^2 q[6,1] <- y^2*y^2 q[6,2] <- 1/4*y^2*y^2+2*1/4*y^2*y*(1-u)+1/4*y*(1-u)*y*(1-u) q[6,3] <- y*(1-u)*y*(1-u) q[6,4] <- 1/16*y^2*y^2+2*1/8*y^2*y*(1-u)+2*1/16*y^2*(1-u)^2+1/4*y*(1-u)*y*(1-u)+2*1/8*y*(1-u)*(1-u)^2+1/16*(1-u)^2*(1-u)^2 q[6,5] <- 1/4*y*(1-u)*y*(1-u)+2*1/4*y*(1-u)*(1-u)^2+1/4*(1-u)^2*(1-u)^2 q[6,6] <- (1-u)^2*(1-u)^2 nu <- rep(0, 6) nu[1] <- num[1,1] #the number of sibships with genotype (AA,AA) nu[2] <- num[1,2] +num[2,1] #the number of sibships with genotype (AA, Aa) or (Aa, AA) nu[3] <- num[1,3] +num[3,1] nu[4] <- num[2,2] nu[5] <- num[2,3] +num[3,2] nu[6] <- num[3,3] nu m<- 100 # the number of iterations pt1<- matrix(0, m, 3) w<- matrix(0, nrow = 6, ncol = 6) pt1[1, ] <- c(0.1, 0.7, 0.2) # initial value t<- 1 while (t