mlpe_rga: Run maximum likelihood population effects mixed effects model...

View source: R/rga_mlpe.R

mlpe_rgaR Documentation

Run maximum likelihood population effects mixed effects model (MLPE)

Description

Runs MLPE as detailed by Clarke et al. (2002). This is a general function for flexibly fitting MLPE models using the standard lme4 formula interface

Usage

mlpe_rga(formula,
                data, 
                REML = FALSE, 
                ZZ = NULL,
                keep = NULL)

Arguments

formula

lme4 style mixed effects model equation.

data

data frame containing vectors of values from the lower half of genetic/resistance distance matrices

REML

Logical. If TRUE, mixed effects model will be fit using restricted maximum likelihood. Default = FALSE

ZZ

The sparse matrix object for the MLPE model. The function will automatically create this object, but it can be specified directly from the output of CS.prep or gdist.prep (Default = NULL)

keep

A vector consisting of 1 (keep) or 0 (drop) for each pairwise observation in data. An option if you do not want to assess all pairiwse observations in the MLPE model.

Details

An AIC value will only be returned if REML = FALSE. The random effect must be the population vector pop1 generated from the function To.From.ID.

A generalized MLPE model can be fit if an appropriate family. It is not possible to use REML when fitting a generalized model.

Value

A lmer object from the fitted model

Author(s)

Bill Peterman <Peterman.73@osu.edu>

References

Clarke, R. T., P. Rothery, and A. F. Raybould. 2002. Confidence limits for regression relationships between distance matrices: Estimating gene flow with distance. Journal of Agricultural, Biological, and Environmental Statistics 7:361-372.

Examples

 
# Create square 'distance' matrices
y <- matrix(rnorm(25), 5)
y.pois <- matrix(rpois(25, 5), 5)
x <- matrix(rnorm(25), 5)

# Create to-from object (5 populations sampled)
id <- To.From.ID(5)

# Create data frame
df <- data.frame(y = lower(y),
                 y.pois = lower(y.pois),
                 x = lower(x),
                 pop = id$pop1)

# Fit MLPE model
out <- mlpe_rga(formula = y ~ x + (1 | pop),
                REML = TRUE,
                data = df)
                
# Fit generalized MLPE model
out.pois <- mlpe_rga(formula = y.pois ~ x + (1 | pop),
                     family = poisson,
                     data = df)
                                
# Fit model with only select pairs
 keep <- c(1,1,1,1,1,1,0,1,1,0)
 
 out.select <- mlpe_rga(formula = y ~ x + (1 | pop),
                        data = df,
                        keep = keep)

wpeterman/ResistanceGA documentation built on Nov. 20, 2023, 11:50 p.m.