Description Usage Arguments Value Author(s) References See Also Examples
Latent Factor Mixed Models (LFMMs) are factor regression models in which the response variable is a genotypic matrix, and the explanatory variables are environmental measures of ecological interest or trait values. The lfmm
function estimates latent factors and effect sizes based on an MCMC algorithm. The resulting object can be used in the function lfmm.pvalues
to identify genetic polymorphisms exhibiting association with ecological gradients or phenotypes, while correcting for unobserved confounders. An exact and computationally efficient leastsquares method is implemented in the function lfmm2
.
1 2 3 4 5 6 7 8 
input.file 
A character string containing a path to the input file,
a genotypic matrix in the 
environment.file 
A character string containing a path to the environmental file,
an environmental data matrix in the 
K 
An integer corresponding to the number of latent factors. 
project 
A character string among "continue", "new", and "force". If "continue", the results are stored in the current project. If "new", the current project is removed and a new project is created. If "force", the results are stored in the current project even if the input file has been modified since the creation of the project. 
d 
An integer corresponding to the fit of an 
all 
A Boolean option. If TRUE, 
missing.data 
A Boolean option. If TRUE, the 
CPU 
A number of CPUs to run the parallel version of the algorithm. By default, the number of CPUs is 1. 
iterations 
The total number of cycles for the Gibbs Sampling algorithm. 
burnin 
The burnin number of cycles for the Gibbs Sampling algorithm. 
seed 
A seed to initialize the random number generator. By default, the seed is randomly chosen. The seed is initialized in each run of the program. For modifying the default setting, provide one seed per run. 
repetitions 
A number of replicate runs for the Gibbs Sampler algorithm. 
epsilon.noise 
A prior parameter for variances. 
epsilon.b 
A prior parameter for the variance of correlation coefficients. 
random.init 
A Boolean option. If TRUE, the Gibbs Sampler is initiliazed randomly. Otherwise, it is initialized with zero values. 
lfmm
returns an object of class lfmmProject
.
The following methods can be applied to an object of class lfmmProject
:
show 
Display information about all analyses. 
summary 
Summarize analyses. 

Return the 

Return the vector of adjusted pvalues for a combination of runs with K latent factors, and for the dth predictor. 
load.lfmmProject (file = "character") 
Load the file containing an lfmmProject objet and show the object. 
remove.lfmmProject (file = "character") 
Erase a 
export.lfmmProject(file.lfmmProject) 
Create a zip file containing the full 
import.lfmmProject(file.lfmmProject) 
Import and load an 
combine.lfmmProject(file.lfmmProject, toCombine.lfmmProject) 
Combine 
Eric Frichot Olivier Francois
Frichot E, Schoville SD, Bouchard G, Francois O. (2013). Testing for associations between loci and environmental gradients using latent factor mixed models. Molecular biology and evolution, 30(7), 16871699.
lfmm.data
z.scores
lfmm.pvalues
pca
lfmm
tutorial
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102  ### Example of analysis using lfmm ###
data("tutorial")
# creation of a genotype file: genotypes.lfmm.
# The file contains 400 SNPs for 50 individuals.
write.lfmm(tutorial.R, "genotypes.lfmm")
# Creation of a phenotype/environment file: gradient.env.
# One environmental predictor for 40 individuals.
write.env(tutorial.C, "gradients.env")
################
# running lfmm #
################
# main options, K: (the number of latent factors),
# CPU: the number of CPUs.
# Runs with K = 6 and 5 repetitions.
# runs with 6000 iterations
# including 3000 iterations for burnin.
# Around 30 seconds per run.
project = lfmm( "genotypes.lfmm",
"gradients.env",
K = 6,
repetitions = 5,
project = "new")
# get adjusted pvalues using all runs
pv = lfmm.pvalues(project, K = 6)
# Evaluate FDR and POWER (TPR)
for (alpha in c(.05,.1,.15,.2)) {
# expected FDR
print(paste("expected FDR:", alpha))
L = length(pv$pvalues)
# BenjaminiHochberg's mehod for an expected FDR = alpha.
w = which(sort(pv$pvalues) < alpha * (1:L)/L)
candidates = order(pv$pvalues)[w]
# estimated FDR and True Positive Rate
# The targets SNPs are loci 351 to 400
Lc = length(candidates)
estimated.FDR = length(which(candidates <= 350))/Lc
estimated.TPR = length(which(candidates > 350))/50
print(paste("FDR:", estimated.FDR, "True Positive Rate:", estimated.TPR))
}
###################
# Posttreatments #
###################
# show the project
show(project)
# summary of the project
summary(project)
# get the zscores for the 2nd run for K = 6
z = z.scores(project, K = 6, run = 2)
# get the pvalues for K = 6 and run 2
p = lfmm.pvalues(project, K = 6, run = 2)
##########################
# Manage an lfmm project #
##########################
# All the runs of lfmm for a given file are
# automatically saved into an lfmm project directory and a file.
# The name of the lfmmProject file is the concatenation of
# the name of the input file and the environment file
# with a .lfmmProject extension ("genotypes_gradient.lfmmProject").
# The name of the lfmmProject directory is the same name as
# the lfmmProject file with a .lfmm extension ("genotypes_gradient.lfmm/")
# There is a unique lfmm Project for each input file.
# An lfmmProject can be loaded in an R session as follows
project = load.lfmmProject("genotypes_gradients.lfmmProject")
# An lfmmProject can be exported to be imported in another directory
# or in another computer as follows
export.lfmmProject("genotypes_gradients.lfmmProject")
dir.create("test", showWarnings = TRUE)
#import
newProject = import.lfmmProject("genotypes_gradients_lfmmProject.zip", "test")
# combine projects
combinedProject < combine.lfmmProject(
"genotypes_gradients.lfmmProject",
"test/genotypes_gradients.lfmmProject"
)
# remove
remove.lfmmProject("test/genotypes_gradients.lfmmProject")
# An lfmmProject can be removed as follows.
# Caution: All the files associated with the project will be removed.
remove.lfmmProject("genotypes_gradients.lfmmProject")

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.