Computes the profile likelihood function for a single coefficient in a model fitted by lm() or glm(), by refitting the model with the coefficient constrained (via an offset) at each point of a grid and recording the maximized log-likelihood. This is the direct likelihood analogue of curve_gen() and requires no external packages. The nuisance parameters are genuinely profiled out – maximized over at every grid point – not fixed at their MLEs.

curve_lik_glm(model, var, range = 5, steps = 200, table = TRUE)

Arguments

model

A fitted lm or glm object.

var

The name of the coefficient of interest, as a character string (e.g. "dose").

range

The number of standard errors on either side of the estimate that the grid should cover. Defaults to 5, which reaches relative likelihoods well below 1/1000.

steps

Number of grid points at which the profile is evaluated. Defaults to 200; each point costs one constrained model refit.

table

Indicates whether or not a table output with some relevant statistics should be generated. The default is TRUE.

Value

A list with 2 items where the dataframe of values is in the first object, and the table for the values in the second if table = TRUE.

Details

The constrained fits use the offset trick: to fix the coefficient of \(x_j\) at \(b\), the term \(b x_j\) is moved into an offset and the model is refit without \(x_j\). For lm objects the equivalent weighted least-squares profile is used. The profile deviance from this function agrees with confint()'s profile-likelihood intervals: the relative likelihood cutoff \(\exp(-\chi^2_{1,0.95}/2) = 1/6.83\) reproduces the 95\

References

Venzon DJ, Moolgavkar SH. A method for computing profile-likelihood- based confidence intervals. J R Stat Soc Ser C Appl Stat. 1988;37(1):87-94.

Cole SR, Chu H, Greenland S. Maximum likelihood, profile likelihood, and penalized likelihood: a primer. Am J Epidemiol. 2014;179(2):252-260.

Examples

if (FALSE) { # \dontrun{
mod <- glm(am ~ mpg, family = binomial, data = mtcars)
lik <- curve_lik_glm(mod, "mpg")
ggcurve(lik[[1]], type = "l1")
curve_support(lik[[1]])
} # }