[adegenet-forum] Hardy-weinberg using R

Jombart, Thibaut t.jombart at imperial.ac.uk
Fri Jan 20 13:21:51 CET 2012


Hello, 

as far as I know Emmanuel Paradis provides excellent support for his users. 

One issue here in your data is that loci are split on two columns. I would also point out that some 'alleles' are actually decimal, which I find very odd.

Anyway, assuming data are OK, this is how you can do it:

####
## read data
x <- read.csv("nist.csv", row.names=1)

## merge loci
newdat <- t(apply(x, 1, function(e) paste(e[seq(1,by=2,le=length(e)/2)], e[seq(2,by=2,le=length(e)/2)], sep="/")))

## get proper loci names
colnames(newdat) <- gsub("[.][0-9]+$", "", colnames(x)[seq(1,by=2,le=ncol(newdat))])

## convert to genind
y <- df2genind(newdat, sep="/", ploidy=2)

## perform HWE test
HWE.test.genind(y)

####

Cheers 

Thibaut


________________________________________
From: Vitor Aguiar [vitor.aguiar at me.com]
Sent: 19 January 2012 19:46
To: Jombart, Thibaut
Cc: adegenet-forum at r-forge.wu-wien.ac.at
Subject: Re: [adegenet-forum] Hardy-weinberg using R

Hi.

I sent an email to the author and he answered me saying that he was able to read my file using:

x <- read.loci("nist.csv", loci.sep=",", row.names=1)

However, I can't do the HWE test, there's the error message below:

"Error in expand.genotype(Nall, ploidy = ploidy, matrix = TRUE):
        object 'ans' not found"

The author said the pegas interpret my data as haploid, which doesn't make sense to test for HW. Maybe I have to present my data in a different way, but he doesn't offer this kind of support...

The exact file I'm using is attached.

Thanks,
Vitor



More information about the adegenet-forum mailing list