strata-methods: Access and manipulate the population strata for genind or...

Description Usage Arguments Details Author(s) See Also Examples

Description

The following methods allow the user to quickly change the strata of a genind or genlight object.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
strata(x, formula = NULL, combine = TRUE, value)

strata(x) <- value

nameStrata(x, value)

nameStrata(x) <- value

splitStrata(x, value, sep = "_")

splitStrata(x, sep = "_") <- value

addStrata(x, value, name = "NEW")

addStrata(x, name = "NEW") <- value

Arguments

x

a genind or genlight object

formula

a nested formula indicating the order of the population strata.

combine

if TRUE (default), the levels will be combined according to the formula argument. If it is FALSE, the levels will not be combined.

value

a data frame OR vector OR formula (see details).

sep

a character indicating the character used to separate hierarchical levels. This defaults to "_".

name

an optional name argument for use with addStrata if supplying a vector. Defaults to "NEW".

Details

Function Specifics

Argument Specifics

These functions allow the user to seamlessly carry all possible population stratification with their genind or genlight object. Note that there are two ways of performing all methods:

They essentially do the same thing except that the modifying assignment method (the one with the "<-") will modify the object in place whereas the non-assignment method will preserve the original object (unless you overwrite it). Due to convention, everything right of the assignment is termed value. To avoid confusion, here is a guide to the argument value for each function:

Details on Formulas

The preferred use of these functions is with a formula object. Specifically, a hierarchical formula argument is used to assign the levels of the strata. An example of a hierarchical formula would be:

~Country/City/Neighborhood

This convention was chosen as it becomes easier to type and makes intuitive sense when defining a hierarchy. Note: it is important to use hiearchical formulas when specifying hierarchies as other types of formulas (eg. ~Country*City*Neighborhood) will give incorrect results.

Author(s)

Zhian N. Kamvar

See Also

setPop genind as.genind

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# let's look at the microbov data set:
data(microbov)
microbov

# We see that we have three vectors of different names in the 'other' slot. 
# ?microbov
# These are Country, Breed, and Species
names(other(microbov))

# Let's set the strata
strata(microbov) <- data.frame(other(microbov))
microbov

# And change the names so we know what they are
nameStrata(microbov) <- ~Country/Breed/Species

## Not run: 
# let's see what the strata looks like by Species and Breed:
head(strata(microbov, ~Breed/Species))

# If we didn't want the last column combined with the first, we can set
# combine = FALSE
head(strata(microbov, ~Breed/Species, combine = FALSE))

#### USING splitStrata ####

# For the sake of example, we'll imagine that we have imported our data set
# with all of the stratifications combined. 
setPop(microbov) <- ~Country/Breed/Species
strata(microbov) <- NULL

# This is what our data would look like after import.
microbov

# To set our strata here, we need to use the functions strata and splitStrata
strata(microbov) <- data.frame(x = pop(microbov))
microbov # shows us that we have "one" level of stratification
head(strata(microbov)) # all strata are separated by "_"

splitStrata(microbov) <- ~Country/Breed/Species
microbov # Now we have all of our strata named and split
head(strata(microbov)) # all strata are appropriately named and split.

## End(Not run)

Example output

Loading required package: ade4

   /// adegenet 2.0.1 is loaded ////////////

   > overview: '?adegenet'
   > tutorials/doc/questions: 'adegenetWeb()' 
   > bug reports/feature requests: adegenetIssues()


/// GENIND OBJECT /////////

 // 704 individuals; 30 loci; 373 alleles; size: 1.1 Mb

 // Basic content
   @tab:  704 x 373 matrix of allele counts
   @loc.n.all: number of alleles per locus (range: 5-22)
   @loc.fac: locus factor for the 373 columns of @tab
   @all.names: list of allele names for each locus
   @ploidy: ploidy of each individual  (range: 2-2)
   @type:  codom
   @call: genind(tab = truenames(microbov)$tab, pop = truenames(microbov)$pop)

 // Optional content
   @pop: population of each individual (group size range: 30-61)
   @other: a list containing: coun  breed  spe 

[1] "coun"  "breed" "spe"  
/// GENIND OBJECT /////////

 // 704 individuals; 30 loci; 373 alleles; size: 1.1 Mb

 // Basic content
   @tab:  704 x 373 matrix of allele counts
   @loc.n.all: number of alleles per locus (range: 5-22)
   @loc.fac: locus factor for the 373 columns of @tab
   @all.names: list of allele names for each locus
   @ploidy: ploidy of each individual  (range: 2-2)
   @type:  codom
   @call: genind(tab = truenames(microbov)$tab, pop = truenames(microbov)$pop)

 // Optional content
   @pop: population of each individual (group size range: 30-61)
   @strata: a data frame with 3 columns ( coun, breed, spe )
   @other: a list containing: coun  breed  spe 

   Breed   Species
1 Borgou Borgou_BI
2 Borgou Borgou_BI
3 Borgou Borgou_BI
4 Borgou Borgou_BI
5 Borgou Borgou_BI
6 Borgou Borgou_BI
   Breed Species
1 Borgou      BI
2 Borgou      BI
3 Borgou      BI
4 Borgou      BI
5 Borgou      BI
6 Borgou      BI
/// GENIND OBJECT /////////

 // 704 individuals; 30 loci; 373 alleles; size: 1.1 Mb

 // Basic content
   @tab:  704 x 373 matrix of allele counts
   @loc.n.all: number of alleles per locus (range: 5-22)
   @loc.fac: locus factor for the 373 columns of @tab
   @all.names: list of allele names for each locus
   @ploidy: ploidy of each individual  (range: 2-2)
   @type:  codom
   @call: genind(tab = truenames(microbov)$tab, pop = truenames(microbov)$pop)

 // Optional content
   @pop: population of each individual (group size range: 30-61)
   @other: a list containing: coun  breed  spe 

/// GENIND OBJECT /////////

 // 704 individuals; 30 loci; 373 alleles; size: 1.1 Mb

 // Basic content
   @tab:  704 x 373 matrix of allele counts
   @loc.n.all: number of alleles per locus (range: 5-22)
   @loc.fac: locus factor for the 373 columns of @tab
   @all.names: list of allele names for each locus
   @ploidy: ploidy of each individual  (range: 2-2)
   @type:  codom
   @call: genind(tab = truenames(microbov)$tab, pop = truenames(microbov)$pop)

 // Optional content
   @pop: population of each individual (group size range: 30-61)
   @strata: a data frame with 1 columns ( x )
   @other: a list containing: coun  breed  spe 

             x
1 AF_Borgou_BI
2 AF_Borgou_BI
3 AF_Borgou_BI
4 AF_Borgou_BI
5 AF_Borgou_BI
6 AF_Borgou_BI
/// GENIND OBJECT /////////

 // 704 individuals; 30 loci; 373 alleles; size: 1.1 Mb

 // Basic content
   @tab:  704 x 373 matrix of allele counts
   @loc.n.all: number of alleles per locus (range: 5-22)
   @loc.fac: locus factor for the 373 columns of @tab
   @all.names: list of allele names for each locus
   @ploidy: ploidy of each individual  (range: 2-2)
   @type:  codom
   @call: genind(tab = truenames(microbov)$tab, pop = truenames(microbov)$pop)

 // Optional content
   @pop: population of each individual (group size range: 30-61)
   @strata: a data frame with 3 columns ( Country, Breed, Species )
   @other: a list containing: coun  breed  spe 

  Country  Breed Species
1      AF Borgou      BI
2      AF Borgou      BI
3      AF Borgou      BI
4      AF Borgou      BI
5      AF Borgou      BI
6      AF Borgou      BI

adegenet documentation built on Oct. 10, 2021, 1:09 a.m.