This function optimizes the log-likelihood over the fixed-effect coefficients and the total variance \(s^2 = \sigma_u^2 + \sigma^2\). When tu.lambda is supplied (random-effects model), heritability \(h^2 = \sigma_u^2 / s^2\) is profiled out via either a grid search or Brent's method.

get_mle(
  input,
  fn.gp,
  m,
  tu.lambda = NULL,
  h2.method = c("brent", "grid"),
  n.grid = 100,
  return.profile = FALSE,
  epsilon = 0.01,
  control = NULL,
  gls = FALSE
)

Arguments

input

A list containing phenotype, genotype, treatment, and subject. The elements must be named "y", "g", "t", and "subject".

fn.gp

A character string specifying the function to model the relationship between the genotype and phenotype. This must be one of "nonlinear" and "linear".

m

A vector of binary indicator variables specifying the exclusion (0) and inclusion (1) of the genotype, treatment, and interaction terms.

tu.lambda

A list containing the transposed eigenvector matrix and the eigenvalues of the covariance matrix (from get_eigen). NULL means no random effect.

h2.method

A character string. "brent" (default) uses Brent's method via optimize to find the MLE of \(h^2\); "grid" evaluates the profile likelihood on a fixed grid. Ignored when tu.lambda is NULL.

n.grid

An integer specifying the number of grid points in \([0, 1-\epsilon]\) when h2.method = "grid". Default is 100.

return.profile

A logical scalar. If TRUE and h2.method = "grid", attach the grid data frame (h2, log_lik) to the returned object as $profile. Default FALSE.

epsilon

A small positive scalar. The upper bound of the \(h^2\) search interval is set to \(1 - \epsilon\). Default is 1e-2. Ignored when tu.lambda is NULL.

control

A list of control parameters passed to optim for the inner BFGS step. If NULL, the defaults are used. Ignored when gls = TRUE.

gls

A logical scalar. If TRUE, use the closed-form generalized least squares (GLS) estimator instead of BFGS to solve for the fixed effects and variance. Only valid when fn.gp = "linear". Default is FALSE.

Value

A list with the elements returned by optim plus:

  • h2 - MLE of heritability (only when ranef=TRUE).

  • profile - Data frame of h2 and log_lik values (only when h2.method="grid" and return.profile=TRUE).