solution4 - Homework 4 solution 1 Problem 1 a For this...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Homework 4 solution 1 Problem 1 a) For this problem, the R code basically follows the lecture notes. In my code, I extended the table with the row sum as the last column and column sum as the last row, so now the table is as follows. Table 1: New table Col1 Col2 Col3 Col4 Col5 Col6 SUM 1 1 2 4 1 1 2 1 2 1 4 3 2 5 2 1 1 1 1 1 7 2 1 3 10 1 3 2 5 4 25 R code: data<-read.table("data.txt") n<-dim(data)[1]-1 m<-dim(data)[2]-1 1 #Exact Tests num<-10000#Sample size weights<-NULL pvalues<-NULL #Generate the tables for(sample in 1:num) { w<-1 p<-1 table<-matrix(0,n+1,m+1) table[n+1,]<-as.matrix(data[n+1,]) table[,m+1]<-as.matrix(data[,m+1]) for(i in 1:(m-1)) { for(j in 1:(n-1)) { n1<-table[n+1,i]-sum(table[c(1:n),i])#Evaluate the new column sums n2<-table[j,m+1]-sum(table[j,c(1:m)])#Evaluate the new row sums l<-max(0,n1-(sum(table[c((j+1):n),m+1])-sum(table[(j+1):n,1:i]))) u<-min(n2,n1) table[j,i]<-rhyper(1,u,u,u+l) w<-w/dhyper(table[j,i],u,u,u+l)/factorial(table[j,i])*factorial(data[j,i]) p<-p/factorial(table[j,i])*factorial(data[j,i])...
View Full Document

This note was uploaded on 10/24/2010 for the course STAT 428 taught by Professor Chen during the Spring '08 term at University of Illinois, Urbana Champaign.

Page1 / 5

solution4 - Homework 4 solution 1 Problem 1 a For this...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online