Title: | Generalized Mixed-Effects Models in Julia |
---|---|
Description: | R package for interfacing with Julia's MixedModels library to fit generalized linear mixed-effects models, similar to the lme4 package in R (<http://dmbates.github.io/MixedModels.jl/latest/>). |
Authors: | Mika Braginsky [aut, cre] |
Maintainer: | Mika Braginsky <[email protected]> |
License: | GPL-3 |
Version: | 0.1.0.9001 |
Built: | 2024-10-25 04:01:56 UTC |
Source: | https://github.com/mikabr/jglmm |
Model Deviance
## S3 method for class 'jglmm' deviance(object, ...)
## S3 method for class 'jglmm' deviance(object, ...)
object |
An object of class 'jglmm', as returned by 'jglmm()'. |
... |
Optional additional arguments, currently none are used. |
A numeric giving the deviance extracted from the fitted model.
## Not run: jglmm_setup() lm1 <- jglmm(Reaction ~ Days + (Days | Subject), lme4::sleepstudy) deviance(lm1) ## End(Not run)
## Not run: jglmm_setup() lm1 <- jglmm(Reaction ~ Days + (Days | Subject), lme4::sleepstudy) deviance(lm1) ## End(Not run)
Extract AIC from a Fitted Model
## S3 method for class 'jglmm' extractAIC(fit, scale = 0, k = 2, ...)
## S3 method for class 'jglmm' extractAIC(fit, scale = 0, k = 2, ...)
fit |
An object of class 'jglmm', as returned by 'jglmm'. |
scale |
Not currently used (see 'extractAIC' generic). |
k |
Numeric specifying the 'weight' of the degrees of freedom part in the AIC formula. |
... |
Optional additional arguments, currently none are used. |
A numeric vector of length 2, with first and second elements giving
‘df' the ’degrees of freedom' for the fitted model in 'x'.
'AIC' the (generalized) Akaike Information Criterion for the fitted model in 'x'.
## Not run: jglmm_setup() lm1 <- jglmm(Reaction ~ Days + (Days | Subject), lme4::sleepstudy) aic <- extractAIC(lm1) bic <- extractAIC(lm1, k = log(nobs(lm1))) ## End(Not run)
## Not run: jglmm_setup() lm1 <- jglmm(Reaction ~ Days + (Days | Subject), lme4::sleepstudy) aic <- extractAIC(lm1) bic <- extractAIC(lm1, k = log(nobs(lm1))) ## End(Not run)
Extract the fitted values from a 'jglmm' object.
## S3 method for class 'jglmm' fitted(object, ...)
## S3 method for class 'jglmm' fitted(object, ...)
object |
An object of class 'jglmm', as returned by 'jglmm()'. |
... |
Optional additional arguments, currently none are used. |
Vector of fitted values extracted from the model.
## Not run: jglmm_setup() cbpp <- dplyr::mutate(lme4::cbpp, prop = incidence / size) gm <- jglmm(prop ~ period + (1 | herd), data = cbpp, family = "binomial", weights = cbpp$size) fitted(gm) ## End(Not run)
## Not run: jglmm_setup() cbpp <- dplyr::mutate(lme4::cbpp, prop = incidence / size) gm <- jglmm(prop ~ period + (1 | herd), data = cbpp, family = "binomial", weights = cbpp$size) fitted(gm) ## End(Not run)
Extract the fixed-effects estimates from a 'jglmm' object.
## S3 method for class 'jglmm' fixef(object, ...)
## S3 method for class 'jglmm' fixef(object, ...)
object |
An object of class 'jglmm', as returned by 'jglmm()'. |
... |
Optional additional arguments, currently none are used. |
A named numeric vector of fixed-effects estimates.
## Not run: jglmm_setup() lm1 <- jglmm(Reaction ~ Days + (Days | Subject), lme4::sleepstudy) fixef(lm1) ## End(Not run)
## Not run: jglmm_setup() lm1 <- jglmm(Reaction ~ Days + (Days | Subject), lme4::sleepstudy) fixef(lm1) ## End(Not run)
Returns the values on the diagonal of the hat matrix, which is the matrix that transforms the response vector (minus any offset) into the fitted values (minus any offset). Note that this method should only be used for linear mixed models. It is not clear if the hat matrix concept even makes sense for generalized linear mixed models.
## S3 method for class 'jglmm' hatvalues(model, ...)
## S3 method for class 'jglmm' hatvalues(model, ...)
model |
An object of class 'jglmm', as returned by 'jglmm()'. |
... |
Optional additional arguments, currently none are used. |
A numeric vector containing the diagonal elements of the hat matrix.
## Not run: jglmm_setup() lm1 <- jglmm(Reaction ~ Days + (Days | Subject), lme4::sleepstudy) hatvalues(lm1) ## End(Not run)
## Not run: jglmm_setup() lm1 <- jglmm(Reaction ~ Days + (Days | Subject), lme4::sleepstudy) hatvalues(lm1) ## End(Not run)
Fitting Generalized Linear Mixed-Effects Models in Julia
jglmm( formula, data, family = "normal", link = NULL, weights = NULL, contrasts = NULL, REML = FALSE ) ## S3 method for class 'jglmm' print(x, ...) ## S3 method for class 'jglmm' summary(object, ...)
jglmm( formula, data, family = "normal", link = NULL, weights = NULL, contrasts = NULL, REML = FALSE ) ## S3 method for class 'jglmm' print(x, ...) ## S3 method for class 'jglmm' summary(object, ...)
formula |
A two-sided linear formula object describing both the fixed-effects and random-effects part of the model, with the response on the left of a ~ operator and the terms, separated by + operators, on the right. Random-effects terms are distinguished by vertical bars ("|") separating expressions for design matrices from grouping factors. |
data |
A data frame containing the variables named in formula. |
family |
(optional) The distribution family for the response variable (defaults to "normal"). |
link |
(optional) The model link function (defaults to "identity"). |
weights |
(optional) A vector of prior case weights. |
contrasts |
(optional) A named list mapping column names of categorical variables in data to coding schemes (defaults to dummy coding all categorical variables). |
REML |
(optional) A logical indicating whether REML should be used
instead of maximum likelihood (defaults to |
x |
An object of class 'jglmm', as returned by 'jglmm()'. |
... |
Optional additional arguments, currently none are used. |
object |
An object of class 'jglmm', as returned by 'jglmm()'. |
An object of class 'jglmm'.
## Not run: jglmm_setup() # linear model lm1 <- jglmm(Reaction ~ Days + (Days | Subject), lme4::sleepstudy) # logistic model cbpp <- dplyr::mutate(lme4::cbpp, prop = incidence / size) gm1 <- jglmm(prop ~ period + (1 | herd), data = cbpp, family = "binomial", weights = cbpp$size) gm2 <- jglmm(prop ~ period + (1 | herd), data = cbpp, family = "binomial", weights = cbpp$size, contrasts = list(period = "effects")) ## End(Not run)
## Not run: jglmm_setup() # linear model lm1 <- jglmm(Reaction ~ Days + (Days | Subject), lme4::sleepstudy) # logistic model cbpp <- dplyr::mutate(lme4::cbpp, prop = incidence / size) gm1 <- jglmm(prop ~ period + (1 | herd), data = cbpp, family = "binomial", weights = cbpp$size) gm2 <- jglmm(prop ~ period + (1 | herd), data = cbpp, family = "binomial", weights = cbpp$size, contrasts = list(period = "effects")) ## End(Not run)
Set up Julia and required libraries
jglmm_setup()
jglmm_setup()
These methods tidy the coefficients and fitted values from 'jglmm' objects.
## S3 method for class 'jglmm' glance(x, ...) ## S3 method for class 'jglmm' tidy(x, ...) ## S3 method for class 'jglmm' augment(x, ...)
## S3 method for class 'jglmm' glance(x, ...) ## S3 method for class 'jglmm' tidy(x, ...) ## S3 method for class 'jglmm' augment(x, ...)
x |
An object of class 'jglmm', as returned by 'jglmm()'. |
... |
Optional additional arguments, currently none are used. |
'glance' returns a data frame with one row and the columns:
'tidy' returns a data frame with one row for each estimated effect. It contains the columns:
effect |
|
group |
the group within which the random effect is being estimated ( |
param |
parameter being estimated ( |
term |
term being estimated |
estimate |
estimated coefficient |
std.error |
standard error |
statistic |
z-statistic ( |
p.value |
p-value computed from z-statistic ( |
'augment' returns one row for each original observation, with these columns added:
.fitted |
predicted values |
.resid |
residuals |
## Not run: jglmm_setup() cbpp <- dplyr::mutate(lme4::cbpp, prop = incidence / size) gm <- jglmm(prop ~ period + (1 | herd), data = cbpp, family = "binomial", weights = cbpp$size) tidy(gm) augment(gm) glance(gm) ## End(Not run)
## Not run: jglmm_setup() cbpp <- dplyr::mutate(lme4::cbpp, prop = incidence / size) gm <- jglmm(prop ~ period + (1 | herd), data = cbpp, family = "binomial", weights = cbpp$size) tidy(gm) augment(gm) glance(gm) ## End(Not run)
Extract Log-Likelihood
## S3 method for class 'jglmm' logLik(object, ...)
## S3 method for class 'jglmm' logLik(object, ...)
object |
An object of class 'jglmm', as returned by 'jglmm()'. |
... |
Optional additional arguments, currently none are used. |
An object of class logLik
, a number with attribute "df"
(degrees of freedom), giving the number of (estimated)
parameters in the model.
## Not run: jglmm_setup() lm1 <- jglmm(Reaction ~ Days + (Days | Subject), lme4::sleepstudy) logLik(lm1) ## End(Not run)
## Not run: jglmm_setup() lm1 <- jglmm(Reaction ~ Days + (Days | Subject), lme4::sleepstudy) logLik(lm1) ## End(Not run)
Extract the Number of Observations from a Fit
## S3 method for class 'jglmm' nobs(object, ...)
## S3 method for class 'jglmm' nobs(object, ...)
object |
An object of class 'jglmm', as returned by 'jglmm()'. |
... |
Optional additional arguments, currently none are used. |
A numeric giving the number of observations.
## Not run: jglmm_setup() lm1 <- jglmm(Reaction ~ Days + (Days | Subject), lme4::sleepstudy) nobs(lm1) ## End(Not run)
## Not run: jglmm_setup() lm1 <- jglmm(Reaction ~ Days + (Days | Subject), lme4::sleepstudy) nobs(lm1) ## End(Not run)
Predictions from a model
## S3 method for class 'jglmm' predict(object, newdata = NULL, type = "link", allow.new.levels = FALSE, ...)
## S3 method for class 'jglmm' predict(object, newdata = NULL, type = "link", allow.new.levels = FALSE, ...)
object |
An object of class 'jglmm', as returned by 'jglmm'. |
newdata |
(optional) A dataframe of new data. |
type |
(optional) A character string - either |
allow.new.levels |
(optional) A logical indicating whether new random
effects levels in |
... |
Optional additional arguments, currently none are used. |
A numeric vector of predicted values
## Not run: jglmm_setup() cbpp <- dplyr::mutate(lme4::cbpp, prop = incidence / size) gm1 <- jglmm(prop ~ period + (1 | herd), data = cbpp, family = "binomial", weights = cbpp$size) predict(gm1) predict(gm1, type = "response") newdata <- with(cbpp, expand.grid(period=unique(period), herd=unique(herd))) predict(gm1, newdata) ## End(Not run)
## Not run: jglmm_setup() cbpp <- dplyr::mutate(lme4::cbpp, prop = incidence / size) gm1 <- jglmm(prop ~ period + (1 | herd), data = cbpp, family = "binomial", weights = cbpp$size) predict(gm1) predict(gm1, type = "response") newdata <- with(cbpp, expand.grid(period=unique(period), herd=unique(herd))) predict(gm1, newdata) ## End(Not run)
Extract the conditional modes of the random effects from a 'jglmm' object.
## S3 method for class 'jglmm' ranef(object, ...)
## S3 method for class 'jglmm' ranef(object, ...)
object |
An object of class 'jglmm', as returned by 'jglmm()'. |
... |
Optional additional arguments, currently none are used. |
A list of data frames, one for each grouping factor for the random effects. The number of rows in the data frame is the number of levels of the grouping factor. The number of columns is the dimension of the random effect associated with each level of the factor. Each of the data frames has an attribute called "postVar", which contains an array for each random-effects term with the variance-covariance matrices for each level of the grouping factor.
## Not run: jglmm_setup() cbpp <- dplyr::mutate(lme4::cbpp, prop = incidence / size) gm <- jglmm(prop ~ period + (1 | herd), data = cbpp, family = "binomial", weights = cbpp$size) ranef(gm) ## End(Not run)
## Not run: jglmm_setup() cbpp <- dplyr::mutate(lme4::cbpp, prop = incidence / size) gm <- jglmm(prop ~ period + (1 | herd), data = cbpp, family = "binomial", weights = cbpp$size) ranef(gm) ## End(Not run)
Extract the estimated standard deviation of the errors, the "residual standard deviation" (also misnamed the "residual standard error"), from a 'jglmm' object.
## S3 method for class 'jglmm' sigma(object, ...)
## S3 method for class 'jglmm' sigma(object, ...)
object |
An object of class 'jglmm', as returned by 'jglmm()'. |
... |
Optional additional arguments, currently none are used. |
Estimate of σ, the standard deviation of the per-observation noise.
## Not run: jglmm_setup() lm1 <- jglmm(Reaction ~ Days + (Days | Subject), lme4::sleepstudy) sigma(lm1) ## End(Not run)
## Not run: jglmm_setup() lm1 <- jglmm(Reaction ~ Days + (Days | Subject), lme4::sleepstudy) sigma(lm1) ## End(Not run)
Simulate responses from a model
## S3 method for class 'jglmm' simulate(object, nsim = 1, seed = NULL, newdata = NULL, ...)
## S3 method for class 'jglmm' simulate(object, nsim = 1, seed = NULL, newdata = NULL, ...)
object |
An object of class 'jglmm', as returned by 'jglmm'. |
nsim |
(optional) A positive integer indicating the number of responses to simulate |
seed |
Not currently used (see 'simulate' generic). |
newdata |
(optional) A dataframe of new data. |
... |
Optional additional arguments, currently none are used. |
A numeric vector of simulated values
## Not run: jglmm_setup() cbpp <- dplyr::mutate(lme4::cbpp, prop = incidence / size) gm1 <- jglmm(prop ~ period + (1 | herd), data = cbpp, family = "binomial", weights = cbpp$size) simulate(gm1) simulate(gm1, nsim = 5) newdata <- with(cbpp, expand.grid(period=unique(period), herd=unique(herd))) simulate(gm1, newdata = newdata) ## End(Not run)
## Not run: jglmm_setup() cbpp <- dplyr::mutate(lme4::cbpp, prop = incidence / size) gm1 <- jglmm(prop ~ period + (1 | herd), data = cbpp, family = "binomial", weights = cbpp$size) simulate(gm1) simulate(gm1, nsim = 5) newdata <- with(cbpp, expand.grid(period=unique(period), herd=unique(herd))) simulate(gm1, newdata = newdata) ## End(Not run)
Extract the variance-covariance matrix of the main parameters from a 'jglmm' object.
## S3 method for class 'jglmm' vcov(object, ...)
## S3 method for class 'jglmm' vcov(object, ...)
object |
An object of class 'jglmm', as returned by 'jglmm()'. |
... |
Optional additional arguments, currently none are used. |
A matrix of the estimated covariances between the parameter estimates in the linear or non-linear predictor of the model.
## Not run: jglmm_setup() lm1 <- jglmm(Reaction ~ Days + (Days | Subject), lme4::sleepstudy) vcov(lm1) ## End(Not run)
## Not run: jglmm_setup() lm1 <- jglmm(Reaction ~ Days + (Days | Subject), lme4::sleepstudy) vcov(lm1) ## End(Not run)