radish_grid: Evaluate likelihood of a parameterized conductance surface

Description Usage Arguments Value Examples

View source: R/radish_grid.R

Description

Calculates the profile likelihood of a parameterized conductance surface across a grid of parameter values (e.g. the nuisance parameters are optimized at each point on the grid).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
radish_grid(
  theta,
  formula,
  data,
  conductance_model = radish::loglinear_conductance,
  measurement_model = radish::mlpe,
  nu = NULL,
  nonnegative = TRUE,
  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)

measurement_model

A function of class radish_measurement_model (see radish_measurement_model)

nu

Number of genetic markers (potentially used by measurement_model)

nonnegative

Force regression-like measurement_model to have nonnegative slope?

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, additionally return (a submatrix of) the generalized inverse of graph Laplacian across the grid

Value

An object of class radish_grid, containing:

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
library(raster)

data(melip)

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

fit_mlpe <- radish(melip.Fst ~ altitude * forestcover, data = surface, 
                   radish::loglinear_conductance, radish::mlpe)

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

grid <- radish_grid(theta, melip.Fst ~ forestcover + altitude, surface,
                    radish::loglinear_conductance, radish::mlpe)

library(ggplot2)
ggplot(data.frame(loglik=grid$loglik, grid$theta), 
       aes(x=forestcover, y=altitude)) + 
  geom_tile(aes(fill=loglik)) + 
  geom_contour(aes(z=loglik), color="black") +
  annotate(geom = "point", colour = "red",
           x = coef(fit_mlpe)["forestcover"], 
           y = coef(fit_mlpe)["altitude"]) +
  theme_bw() +
  xlab(expression(theta[altitude])) +
  ylab(expression(theta[forestcover]))

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