Hi,
   
  I cant understand where I am going wrong.Below is my code.I would really appreciate your help.
   
  Thanks.
   
   
  > genfile<-read.table("c:/tina/phd/bs871/hw/genfile.txt",skip=1)
> 
> #read in SNP data
> snp.dat <- as.matrix(genfile)
> snp.name <- scan("c:/tina/phd/bs871/hw/genfile.txt",nline=1,what="character")
Read 100 items
> n.snp <- length(snp.name)
> n.id <- 1 #number of fields for ids, sex and affection status
> 
> ###form gntp using the two alleles of each SNP
> allele1 <- snp.dat[,seq(1,2*n.snp,2)+n.id ]
> allele2 <- snp.dat[,seq(2,2*n.snp,2)+n.id ]
> temp <- matrix(paste(allele1,allele2,sep="|"),dim(allele1))
> temp <- data.frame(temp)
> convt <- function(x) x <- factor(as.character(x),exclude="0|0")
> 
> gntp <- as.data.frame(lapply(temp,convt))
> 
> ###create new snp data with ids and gntp only
> names(gntp) <- snp.name
> ids <- as.data.frame(snp.dat[,1:n.id])
> names(ids) <- c("fid")
> 
> snp.dat <- cbind(ids,gntp)
> 
> 
> 
> #read in phenotype data
> #------------------------------------------------------
> phen.dat <- read.table("c:/tina/phd/bs871/fram.csv",header=T,sep=",",na.string='')
> phen.name <- scan("c:/tina/phd/bs871/fram.csv",nline=1,what="character")
Read 1 item
> n.phen <- length(phen.name)
> 
> names(phen.dat) <- c("id", phen.name)
> 
> test.allsnp <- function(phen)
+ 
+ apply(phen.dat[,snp.name],glm.reg,phen=phen)
> ##Above:since snp gntp data are defined as factor, use lapply instead of apply(matrix only)
> 
> #Below; apply() results in three dimensional list (phen,snp)
> #use unlist to convert the list into a vector, then use matrix to convert the vector
> #into a matrix of 15 columns, each row for a (phen,snp) combination with byrow=T  
> 
> final <- matrix(unlist(apply(phen.dat[,phen.name],2,test.allsnp)),byrow=T,ncol=15)
Error in apply(phen.dat[, phen.name], 2, test.allsnp) : 
        dim(X) must have a positive length
> 
> 


		
---------------------------------

	[[alternative HTML version deleted]]


