leastsquares: (Nonnegative) least squares

Description Usage Arguments Details Value See Also Examples

View source: R/leastsquares.R

Description

A function of class measurement_model that calculates likelihood, gradient, hessian, and partial derivatives of nuisance parameters and the Laplacian generalized inverse, using nonnegative least squares.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
leastsquares(
  E,
  S,
  phi,
  nu = NULL,
  gradient = TRUE,
  hessian = TRUE,
  partial = TRUE,
  nonnegative = TRUE,
  validate = FALSE
)

Arguments

E

A submatrix of the generalized inverse of the graph Laplacian (e.g. a covariance matrix)

S

A matrix of observed genetic distances

phi

Nuisance parameters (see details)

nu

Unused

gradient

Compute gradient of negative loglikelihood with regard to phi?

hessian

Compute Hessian matrix of negative loglikelihood with regard to phi?

partial

Compute second partial derivatives of negative loglikelihood with regard to phi, E, S?

nonnegative

Force slope to be nonnegative?

validate

Numerical validation via package numDeriv (very slow, use for debugging small examples)

Details

The nuisance parameters phi are the intercept ("alpha"), slope ("beta"), and negative log residual standard deviation ("tau") of the least squares regression. If not supplied, phi is estimated via maximum likelihood by nlme::gls.

TODO: formula

Value

A list containing:

covariance

rows/columns of the generalized inverse of the graph Laplacian for a subset of target vertices

objective

(if objective) the negative loglikelihood

fitted

((if objective) a matrix of expected genetic distances among target vertices

boundary

(if objective) is the MLE on the boundary (e.g. no genetic structure)?

gradient

(if gradient) gradient of negative loglikelihood with respect to phi

hessian

(if hessian) Hessian matrix of the negative loglikelihood with respect to phi

gradient_E

(if partial) gradient with respect to the generalized inverse of the graph Laplacian

partial_E

(if partial) Jacobian of gradient_E with respect to phi

partial_S

(if partial) Jacobian of gradient with respect to S

jacobian_E

(if partial) a function used for reverse algorithmic differentiation

jacobian_S

(if partial) a function used for reverse algorithmic differentiation

See Also

radish_measurement_model

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=melip.altitude, forestcover=melip.forestcover))
surface <- conductance_surface(covariates, melip.coords, directions = 8)

# inverse of graph Laplacian at null model (IBD) 
laplacian_inv <- radish_distance(theta = matrix(0, 1, 2), 
                                 formula = ~forestcover + altitude,
                                 data = surface,
                                 radish::loglinear_conductance, 
                                 covariance = TRUE)$covariance[,,1]

leastsquares(laplacian_inv, melip.Fst) #without 'phi': return MLE of phi
leastsquares(laplacian_inv, melip.Fst, phi = c(0., 0.5, -0.1))

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