radish_distance: Resistance distances from a parameterized conductance surface

Description Usage Arguments Value Examples

View source: R/radish_grid.R

Description

Calculates resistance distances associated with a parameterized conductance surface across a grid of parameter values.

Usage

1
2
3
4
5
6
7
8
radish_distance(
  theta,
  formula,
  data,
  conductance_model = radish::loglinear_conductance,
  conductance = TRUE,
  covariance = FALSE
)

Arguments

theta

A matrix of dimension (grid size) x (number of parameters)

formula

A formula with the name of a matrix of observed genetic distances on the lhs, and covariates in the creation of data on the rhs

data

An object of class radish_graph (see conductance_surface)

conductance_model

A function of class radish_conductance_model_factory (see radish_conductance_model_factory)

conductance

If TRUE, edge conductance is the sum of cell conductances; otherwise edge conductance is the inverse of the sum of cell resistances (unused; TODO)

covariance

If TRUE, instead of a matrix of resistance distances, return the associated submatrix of the generalized inverse of graph Laplacian

Value

An object of class radish_grid

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
library(raster)

data(melip)

covariates <- raster::stack(list(altitude = raster::scale(melip.altitude), 
                                 forestcover = raster::scale(melip.forestcover)))

theta <- as.matrix(expand.grid(forestcover=seq(-1,1,length.out=21), 
                               altitude=seq(-1,1,length.out=21)))

distances <- radish_distance(theta, ~forestcover + altitude, 
                             surface, radish::loglinear_conductance)

ibd <- which(theta[,1] == 0 & theta[,2] == 0)
plot(distances$distance[,,ibd], melip.Fst, pch = 19, 
     xlab = "Null resistance distance (IBD)", ylab = "Fst")

nspope/radish documentation built on July 12, 2020, 11:50 a.m.