[adegenet-forum] unable to find an inherited method for function ‘pop’ for signature ‘"matrix"’

Jombart, Thibaut t.jombart at imperial.ac.uk
Tue Oct 20 15:11:53 CEST 2015

Hi there,

pop() is an accessor defined for genind objects, and does not work with matrices, which is your problem here: data_full is not a genind, but a matrix.

Please check the basics tutorial for more on data handling in adegenet.

Also, scaleGen is now deprecated, better to use 'tab' instead.


From: adegenet-forum-bounces at lists.r-forge.r-project.org [adegenet-forum-bounces at lists.r-forge.r-project.org] on behalf of Ella Bowles [ebowles at ucalgary.ca]
Sent: 19 October 2015 20:44
To: adegenet-forum at lists.r-forge.r-project.org
Subject: [adegenet-forum] unable to find an inherited method for function ‘pop’ for signature ‘"matrix"’


I'm working my way through the DAPC manual for genind objects, and after trying to run
> table(pop(data_full), NumClust$grp)

#got the error

Error in (function (classes, fdef, mtable)  :
  unable to find an inherited method for function ‘pop’ for signature ‘"matrix"’

My full dataset has the name data_full (equivalent to the "x" dataset name in the manual), and the NumClust variable contains the information from the find.cluster section (equivalent to the "grp" variable used in the manual).

I'm wondering if you know what could cause this.

Commands that I have executed thus are are:

data <- read.structure("C:/Users/Ella Bowles/Documents/PhD Ecology Evolution/Data/GBS_2013_run/stacks_run_08/populations_08c9 results_this is the data used for pop gen and genet architec chaps/batch_1_8c9_modified.stru", n.ind = 186, n.loc = 4099, onerowperind = FALSE, col.lab = 1, col.pop = 2, col.others = NULL, row.marknames = 2, NA.char = "0", ask = TRUE)


#slots are accessed using both @ and $ (data are S4 object)



#there are [1] 76822 missing data

#replace them with scaleGen

#calling new dataset "data_full)
data_full <- scaleGen(data, NA.method="mean")


#note disable scaling in dudi.pca, which would erase scaling choice made earlier in scaleGen

NumClust <- find.clusters(data_full, max.n.clust=150)
150 #number of PCs to retain
20 #choosing number of clusters

#[1] "Kstat" "stat"  "grp"   "size"

head(NumClust$Kstat, 20) #BIC for different values of k
# K=1      K=2      K=3      K=4      K=5      K=6      K=7      K=8      K=9     K=10     K=11     K=12     K=13
1660.250 1652.460 1646.640 1645.846 1647.815 1648.798 1650.835 1654.304 1657.618 1661.039 1664.529 1668.123 1671.439
    K=14     K=15     K=16     K=17     K=18     K=19     K=20
1675.647 1678.779 1682.386 1685.970 1689.871 1693.475 1697.183
#looks like k=4 is best

#some other stats that I didn't find useful, see p 6 of dapc manual

head(NumClust$grp, 20)

NumClust$size #group sizes
# [1]  5  6  4  1 19  2 16  3  1 12  7 15 11  2  1 14  7 14 45  1

table(pop(data_full), NumClust$grp)

Many thanks,

Ella Bowles
PhD Candidate
Biological Sciences
University of Calgary

e-mail: ebowles at ucalgary.ca<mailto:ebowles at ucalgary.ca>, bowlese at gmail.com<mailto:bowlese at gmail.com>
website: http://ellabowlesphd.wordpress.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/adegenet-forum/attachments/20151020/54e4b915/attachment.html>

More information about the adegenet-forum mailing list