| Title: | A Package for BInary Longitudinal Data |
|---|---|
| Description: | Performs logistic regression for binary longitudinal data, allowing for serial dependence among observations from a given individual and a random intercept term. Estimation is via maximization of the exact likelihood of a suitably defined model. Missing values and unbalanced data are allowed, with some restrictions. M. Helena Goncalves et al. (2012) <DOI: 10.18637/jss.v046.i09>. |
| Authors: | M. Helena Goncalves [aut, cre] (ORCID: <https://orcid.org/0000-0002-6990-7239>), M. Salome Cabral [aut], Adelchi Azzalini [aut], R. Piessens [ctb] (Author of Fortran-77 subroutines from Quadpack), E. de Doncker [ctb] (Author of Fortran-77 subroutines from Quadpack) |
| Maintainer: | M. Helena Goncalves <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 1.3-0 |
| Built: | 2026-10-17 11:21:47 UTC |
| Source: | https://github.com/cran/bild |
Performs logistic regression for binary longitudinal data, allowing for serial dependence among observations from a given individual and a random intercept term. Estimation is via maximization of the exact likelihood of a suitably defined model. Missing values and unbalanced data are allowed, with some restrictions. M. Helena Goncalves et al. (2012) doi: 10.18637/jss.v046.i09.
Maintainer: M. Helena Goncalves [email protected] (ORCID)
Authors:
M. Salome Cabral
Adelchi Azzalini
Other contributors:
R. Piessens (Author of Fortran-77 subroutines from Quadpack) [contributor]
E. de Doncker (Author of Fortran-77 subroutines from Quadpack) [contributor]
This example is a subset of data from the Six Cities study, a longitudinal study of the health effects of air pollution (Ware, J. H. et al., 1984).
airpollutionairpollution
A data frame with 128 observations on the following 5 variables:
ididentifies the number of the individual profile, containing 32 individual profiles.
wheezea numeric vector that identifies the wheezing status (1="yes", 0="no").
agea numeric vector corresponding to the age in years since the child's 9th birthday.
smokinga factor that identifies if the mother smokes (1="smoke", 0="no smoke").
countsa numeric vector corresponding to the replications of each individual profile.
The data set presented by Fitzmaurice and Laird (1993) contains complete records on 537 children from Steubenville, Ohio. The repeated binary response is the wheezing status of a child. Maternal smoking status was determined in the first interview and treated as a time-independent covariate.
Fitzmaurice, G. M. and Laird, N. M. (1993). A Likelihood-Based Method for analyzing Longitudinal Binary Response. Biometrika, 80, 141-51.
data(airpollution) str(airpollution) # Dependence="MC2" air2 <- bild(wheeze~age+smoking, data=airpollution, time="age", aggregate=smoking, dependence="MC2") summary(air2) getAIC(air2) getLogLik(air2) # Base graphics diagnostics plot(air2) # ggplot2-based diagnostics library(ggplot2) autoplot(air2, which = 1) # Residuals vs Fitted values autoplot(air2, which = 2) # Standardized Residuals vs Time autoplot(air2, which = 5) # Estimated Parametric Profiles # Multi-panel diagnostic plots using patchwork library(patchwork) (autoplot(air2, which = 5) + autoplot(air2, which = 2)) / (autoplot(air2, which = 1) + autoplot(air2, which = 3)) # Dependence="MC2R" air2r <- bild(wheeze~age+smoking, data=airpollution, time="age", aggregate=smoking, dependence="MC2R") summary(air2r) # Compare base plot with autoplot for individual profiles plot(air2r, which=6, subSET=smoking=="0", main="smoking==0", ident=TRUE) autoplot(air2r, which=6, subSET=smoking=="0", ident=TRUE)data(airpollution) str(airpollution) # Dependence="MC2" air2 <- bild(wheeze~age+smoking, data=airpollution, time="age", aggregate=smoking, dependence="MC2") summary(air2) getAIC(air2) getLogLik(air2) # Base graphics diagnostics plot(air2) # ggplot2-based diagnostics library(ggplot2) autoplot(air2, which = 1) # Residuals vs Fitted values autoplot(air2, which = 2) # Standardized Residuals vs Time autoplot(air2, which = 5) # Estimated Parametric Profiles # Multi-panel diagnostic plots using patchwork library(patchwork) (autoplot(air2, which = 5) + autoplot(air2, which = 2)) / (autoplot(air2, which = 1) + autoplot(air2, which = 3)) # Dependence="MC2R" air2r <- bild(wheeze~age+smoking, data=airpollution, time="age", aggregate=smoking, dependence="MC2R") summary(air2r) # Compare base plot with autoplot for individual profiles plot(air2r, which=6, subSET=smoking=="0", main="smoking==0", ident=TRUE) autoplot(air2r, which=6, subSET=smoking=="0", ident=TRUE)
Computes an analysis of deviance table for two or more fitted model
objects of class bild.
## S4 method for signature 'bild' anova(object, ..., test = TRUE, correct = FALSE)## S4 method for signature 'bild' anova(object, ..., test = TRUE, correct = FALSE)
object |
An object of class |
... |
Additional objects of class |
test |
Logical. If TRUE, the likelihood ratio test is performed. Default is TRUE. |
correct |
Logical. If TRUE, a correction for the likelihood ratio test is applied (e.g., for mixture models). Default is FALSE. |
Setting correct = TRUE is used to test the presence of a random intercept term;
the solution proposed by Self and Liang (1987) is adopted for the p-value.
The comparison between two models by anova will only be valid if they
are fitted to the same dataset.
Self, Steven G. and Liang, Kung-Yee (1987). Asymptotic properties of maximum likelihood estimators and likelihood ratio tests under nonstandard conditions. Journal of the American Statistical Association, 82, 605-610.
data(locust) loc1 <- bild::bild(move~(time+I(time^2))*feed*sex, data=locust, dependence="MC1") loc2 <- bild::bild(move~(time+I(time^2))*feed, data=locust, dependence="MC1") anova(loc1, loc2) data(muscatine) muscatine$time1 <- c(-1, 0, 1) musc1 <- bild::bild(obese~time1, data=muscatine, time="time1", dependence="MC1") musc1r <- bild::bild(obese~time1, data=muscatine, time="time1", dependence="MC1R") anova(musc1, musc1r, correct=TRUE)data(locust) loc1 <- bild::bild(move~(time+I(time^2))*feed*sex, data=locust, dependence="MC1") loc2 <- bild::bild(move~(time+I(time^2))*feed, data=locust, dependence="MC1") anova(loc1, loc2) data(muscatine) muscatine$time1 <- c(-1, 0, 1) musc1 <- bild::bild(obese~time1, data=muscatine, time="time1", dependence="MC1") musc1r <- bild::bild(obese~time1, data=muscatine, time="time1", dependence="MC1R") anova(musc1, musc1r, correct=TRUE)
bild Objects using ggplot2
Generates ggplot2-based diagnostic and profile plots for a fitted
bild longitudinal model object.
## S3 method for class 'bild' autoplot(object, which = 5, add.unadjusted = FALSE, subSET, ident = FALSE, ...)## S3 method for class 'bild' autoplot(object, which = 5, add.unadjusted = FALSE, subSET, ident = FALSE, ...)
object |
A fitted model object of class |
which |
A numeric value from 1 to 6 specifying the plot type. |
add.unadjusted |
Logical. |
subSET |
An optional logical expression to subset individuals in plot 6. |
ident |
Logical. |
... |
Further arguments passed. |
A ggplot object.
library(ggplot2) library(patchwork) library(bild) data(airpollution) air1R <- bild::bild(wheeze ~ age + smoking, data = airpollution, time = "age", aggregate = smoking, dependence = "MC1R") # Single diagnostic plot (Standardized Residuals vs Time) autoplot(air1R, which = 2) # Multi-panel diagnostic plots using patchwork (autoplot(air1R, which = 5) + autoplot(air1R, which = 2)) / (autoplot(air1R, which = 1) + autoplot(air1R, which = 3)) # Individual mean profiles for the smoker group autoplot(air1R, which = 6, subSET = smoking == "1", ident = TRUE)library(ggplot2) library(patchwork) library(bild) data(airpollution) air1R <- bild::bild(wheeze ~ age + smoking, data = airpollution, time = "age", aggregate = smoking, dependence = "MC1R") # Single diagnostic plot (Standardized Residuals vs Time) autoplot(air1R, which = 2) # Multi-panel diagnostic plots using patchwork (autoplot(air1R, which = 5) + autoplot(air1R, which = 2)) / (autoplot(air1R, which = 1) + autoplot(air1R, which = 3)) # Individual mean profiles for the smoker group autoplot(air1R, which = 6, subSET = smoking == "1", ident = TRUE)
Performs the fit of parametric models via likelihood method. Serial dependence and random intercept are allowed according to the stochastic model chosen. Missing values and unbalanced data are automatically accounted for computing the likelihood function.
bild( formula = formula(data), data, time, id, subSET, aggregate = FALSE, start = NULL, trace = FALSE, dependence = "ind", method = "BFGS", control = bildControl(), integrate = bildIntegrate() )bild( formula = formula(data), data, time, id, subSET, aggregate = FALSE, start = NULL, trace = FALSE, dependence = "ind", method = "BFGS", control = bildControl(), integrate = bildIntegrate() )
formula |
a description of the model to be fitted of the form |
data |
a data frame containing the variables in the formula. |
time |
a string that matches the name of the |
id |
a string that matches the name of the |
subSET |
an optional expression indicating a subset of the rows of |
aggregate |
a string that permits the user to identify the factor to be used in |
start |
a vector of initial values for the nuisance parameters. |
trace |
logical; if TRUE, details of the nonlinear optimization are printed. |
dependence |
a character string stating which dependence structure to use: "ind", "MC1", "MC2", "indR", "MC1R", "MC2R". Default is "ind". |
method |
the optimization method used by |
control |
a list of control parameters for |
integrate |
a list of algorithmic constants for numerical integration (Fortran-77/QUADPACK). |
The underlying methodology builds a logistic regression model for the probability that the response variable takes value 1 as a function of the covariates, taking into account that successive observations from the same individual cannot be assumed to be independent.
An object of class bild.
Azzalini, A. (1994). Logistic regression for autocorrelated data with application to repeated measures. Biometrika, 81, 767-775. Goncalves, M. H., Cabral, M. S., and Azzalini, A. (2012). The R Package bild for the Analysis of Binary Longitudinal Data. Journal of Statistical Software, 46(9), 1-17.
# Example with airpollution data data(airpollution) air2r <- bild(wheeze~age+smoking, data=airpollution, trace=TRUE, time="age", aggregate=smoking, dependence="MC2R") summary(air2r)# Example with airpollution data data(airpollution) air2r <- bild(wheeze~age+smoking, data=airpollution, trace=TRUE, time="age", aggregate=smoking, dependence="MC2R") summary(air2r)
This class encapsulates results of a maximum likelihood procedure
and is usually created as the result of a call to bild.
coefficientsMatrix. Estimated parameters.
seMatrix. Standard errors of estimated parameters.
covarianceMatrix. Covariance of estimated parameters.
correlationMatrix. Correlation of estimated parameters.
log.likelihoodNumeric. The value of the log likelihood.
messageInteger. Information returned by the optimizer.
n.casesNumeric. Number of individual profiles used in the optimization.
ni.casesNumeric. Number of individual profiles in the dataset.
aicNumeric. The Akaike information criterion.
residualsNumeric. The residuals of estimated parameters.
s.residualsNumeric. The residuals summed over the individual profile.
ind.probabilityNumeric. The transition probabilities.
prob.matrixMatrix. The matrix of transition probabilities.
FittedNumeric. The fitted values for the estimated parameters.
bi.estimateMatrix. The estimated values for the individual random effects.
Fitted.avNumeric. The average fitted values.
TimeNumeric. Vector of time points.
model.matrixMatrix. The model matrix.
y.matrixMatrix. The matrix of response values.
subset.dataData.frame. The data subset if considered.
y.avNumeric. The average of the response value over an individual profile.
f.valueFactor. Indicates the aggregation factor if present.
callLanguage. The call to "bild".
Auxiliary function as user interface for bild fitting.
bildControl(maxit = 100, abstol = 1e-06, reltol = 1e-06)bildControl(maxit = 100, abstol = 1e-06, reltol = 1e-06)
maxit |
maximum number of iterations. |
abstol |
absolute convergence tolerance. |
reltol |
relative convergence tolerance. |
See R documentation of optim for details of standard default values
for the remaining options not considered in bildControl.
A list with the arguments as components.
Auxiliary function as user interface for bild fitting to set
integration constants used in numerical integration.
bildIntegrate( li = -4, ls = 4, epsabs = .Machine$double.eps^0.25, epsrel = .Machine$double.eps^0.25, limit = 100, key = 6, lig = -4, lsg = 4 )bildIntegrate( li = -4, ls = 4, epsabs = .Machine$double.eps^0.25, epsrel = .Machine$double.eps^0.25, limit = 100, key = 6, lig = -4, lsg = 4 )
li |
lower limit of integration for the log-likelihood. |
ls |
upper limit of integration for the log-likelihood. |
epsabs |
absolute accuracy requested. |
epsrel |
relative accuracy requested. |
limit |
integer that gives an upperbound on the number of subintervals. |
key |
integer from 1 to 6 for choice of local integration rule (Gauss-Kronrod). |
lig |
lower limit of integration for the gradient. |
lsg |
upper limit of integration for the gradient. |
bildIntegrate returns a list of constants used to compute integrals based on
a Fortran-77 subroutine dqage from the QUADPACK package.
The numerical integration is performed over the interval (li * , ls * ),
where . If integration produces errors or NaNs in the information
matrix, users should adjust li, ls, lig, or lsg.
For datasets with a high number of time points (> 30), it is recommended to set integration limits to smaller values than the default.
A list with the arguments as components.
library(bild) data(locust) # Example using locust data Integ <- bildIntegrate(li = -2.5, ls = 2.5, lig = -2.5, lsg = 2.5) locust2r_feed1 <- bild(move ~ (time + I(time^2)) * sex, data = locust, subSET = feed == "1", aggregate = sex, dependence = "MC2R", integrate = Integ)library(bild) data(locust) # Example using locust data Integ <- bildIntegrate(li = -2.5, ls = 2.5, lig = -2.5, lsg = 2.5) locust2r_feed1 <- bild(move ~ (time + I(time^2)) * sex, data = locust, subSET = feed == "1", aggregate = sex, dependence = "MC2R", integrate = Integ)
Fitted values for 'bild' objects
## S4 method for signature 'bild' fitted(object, ...)## S4 method for signature 'bild' fitted(object, ...)
object |
an object of class |
... |
Additional arguments. |
A numeric vector of the fitted values.
Extract fixed effects estimates
## S4 method for signature 'bild' fixeff(object)## S4 method for signature 'bild' fixeff(object)
object |
an object of class |
A matrix or vector containing the fixed effects estimates.
Extract the Akaike Information Criterion
## S4 method for signature 'bild' getAIC(object)## S4 method for signature 'bild' getAIC(object)
object |
an object of class |
Returns a numeric value corresponding to the AIC of the fitted model.
Extract the coefficient estimates
## S4 method for signature 'bild' getcoef(object)## S4 method for signature 'bild' getcoef(object)
object |
an object of class |
Returns the coefficient estimates of the fitted model (a matrix).
Extract Log-Likelihood
## S4 method for signature 'bild' getLogLik(object)## S4 method for signature 'bild' getLogLik(object)
object |
an object of class |
Returns a numeric value corresponding to the log-Likelihood of the fitted model.
These functions extract the variance estimate of the random effect ()
from an object of class bild.
## S4 method for signature 'bild' getVariance(object, se = FALSE)## S4 method for signature 'bild' getVariance(object, se = FALSE)
object |
an object of class |
se |
logical; if |
A data frame containing the variance estimate.
Extract variance-covariance matrix
## S4 method for signature 'bild' getvcov(object)## S4 method for signature 'bild' getvcov(object)
object |
an object of class |
Returns a numeric matrix corresponding to the variance-covariance matrix of the fitted model.
bild objectGlance at a fitted longitudinal model object of class bild
to extract a single-row summary tibble with key statistics.
## S3 method for class 'bild' glance(x, ...)## S3 method for class 'bild' glance(x, ...)
x |
A fitted model object of class |
... |
Additional arguments. Not used. |
A tibble::tibble with summary statistics (number of observations,
degrees of freedom/parameters, log-likelihood, AIC, and BIC).
library(bild) library(generics) data(airpollution) air1R <- bild::bild(wheeze ~ age + smoking, data = airpollution, time = "age", aggregate = smoking, dependence = "MC1R") glance(air1R)library(bild) library(generics) data(airpollution) air1R <- bild::bild(wheeze ~ age + smoking, data = airpollution, time = "age", aggregate = smoking, dependence = "MC1R") glance(air1R)
This data set was presented by MacDonald and Raubenheimer (1995) and analyzes the effect of hunger on locomotory behaviour of 24 locusts (Locusta migratoria) observed at 161 time points.
locustlocust
A data frame with 3864 observations on the following 5 variables:
ida numeric vector that identifies the number of the individual profile.
movea numeric vector representing the response variable (1="moving", 0="not moving").
sexa factor with levels 1 for "male" and 0 for "female".
timea numeric vector that identifies the number of the time points observed.
feeda factor with levels 0 "no" and 1 "yes".
MacDonald, I. and Raubenheimer, D. (1995). Hidden Markov models and animal behaviour. Biometrical Journal, 37, 701-712.
data(locust) str(locust) # Dependence="MC2" (Fast computation) locust2_feed1 <- bild(move ~ (time + I(time^2)) * sex, data = locust, subSET = feed == "1", aggregate = sex, dependence = "MC2") summary(locust2_feed1) # Base plot diagnostics (Standard) plot(locust2_feed1, which = 5, ylab = "probability of locomoting", main = "Feed=1", add.unadjusted = TRUE) # ggplot2-based diagnostic plots (New) library(ggplot2) # Comparing which=5 with the base plot above autoplot(locust2_feed1, which = 5) # Other diagnostic plots autoplot(locust2_feed1, which = 1) autoplot(locust2_feed1, which = 2)data(locust) str(locust) # Dependence="MC2" (Fast computation) locust2_feed1 <- bild(move ~ (time + I(time^2)) * sex, data = locust, subSET = feed == "1", aggregate = sex, dependence = "MC2") summary(locust2_feed1) # Base plot diagnostics (Standard) plot(locust2_feed1, which = 5, ylab = "probability of locomoting", main = "Feed=1", add.unadjusted = TRUE) # ggplot2-based diagnostic plots (New) library(ggplot2) # Comparing which=5 with the base plot above autoplot(locust2_feed1, which = 5) # Other diagnostic plots autoplot(locust2_feed1, which = 1) autoplot(locust2_feed1, which = 2)
Extract the fixed effects model matrix
## S4 method for signature 'bild' model.mat(object)## S4 method for signature 'bild' model.mat(object)
object |
an object of class |
Returns the fixed effects model matrix of the fitted model.
This example is a subset of data from the Muscatine Coronary Risk Factor Study, a longitudinal study of coronary risk factors in school children from Muscatine (Iowa, USA).
muscatinemuscatine
A data frame with 156 observations on the following 5 variables:
ididentifies the number of the individual profile.
obesea numeric vector that identifies the obesity status (1="yes", 0="no").
sexa factor with levels 1 for "female" and 0 for "male".
timea numeric vector (1,2,3) indicating the observed time points.
countsa numeric vector indicating the number of times that each profile is replicated.
Fitzmaurice, G. M., Laird, N. M. and Lipsitz, S. R. (1994). Analyzing incomplete longitudinal binary responses: a likelihood based approach. Biometrics, 38, 602-612.
data(muscatine) str(muscatine) # we decompose the time effect in orthogonal components muscatine$time1 <- c(-1, 0, 1) muscatine$time2 <- c(1, -2, 1) # second order Markov Chain without random effects musc2 <- bild(obese~(time1+time2)*sex, data=muscatine, time="time1", aggregate=sex, trace=TRUE, dependence="MC2") summary(musc2) getAIC(musc2) getLogLik(musc2) fitted(musc2)data(muscatine) str(muscatine) # we decompose the time effect in orthogonal components muscatine$time1 <- c(-1, 0, 1) muscatine$time2 <- c(1, -2, 1) # second order Markov Chain without random effects musc2 <- bild(obese~(time1+time2)*sex, data=muscatine, time="time1", aggregate=sex, trace=TRUE, dependence="MC2") summary(musc2) getAIC(musc2) getLogLik(musc2) fitted(musc2)
Diagnostic and profile plots for a fitted bild
longitudinal model object using standard R base graphics. Six plots
(selectable by which) are currently available. By default,
the first five are provided.
## S4 method for signature 'bild,missing' plot( x, y, which = c(1:5), ylab = NULL, main = NULL, ask = prod(par("mfcol")) < length(which) && dev.interactive(), subSET, add.unadjusted = FALSE, ident = FALSE, caption = c("Residuals vs Fitted", "Residuals vs Time", "ACF residuals", "PACF residuals", "Individual mean profiles"), cex.caption = 1 )## S4 method for signature 'bild,missing' plot( x, y, which = c(1:5), ylab = NULL, main = NULL, ask = prod(par("mfcol")) < length(which) && dev.interactive(), subSET, add.unadjusted = FALSE, ident = FALSE, caption = c("Residuals vs Fitted", "Residuals vs Time", "ACF residuals", "PACF residuals", "Individual mean profiles"), cex.caption = 1 )
x |
An object of class |
y |
Not used. Must be missing. |
which |
If a subset of the plots is required, specify a subset of the numbers 1:6:
|
ylab |
Label to some plots ( |
main |
Title to some plots in addition to the caption ( |
ask |
Logical expression; if |
subSET |
Logical expression indicating elements to keep in individual mean
profile plots: missing values are taken as |
add.unadjusted |
Logical expression indicating whether or not to add
the unadjusted fit for plot in |
ident |
Logical expression indicating whether or not to add the number
of the subject to individual mean profile plots. The |
caption |
Captions to appear above the plots. Defaults to a vector of standard labels. |
cex.caption |
Controls the font size expansion factor for the caption. |
The option which=5 provides the parametric fitted model if the dependence
structure is "ind" (independence), "MC1" (first order Markov Chain) or "MC2"
(second order Markov Chain).
When the dependence structure is "indR" (independence with random intercept),
"MC1R" (first order Markov Chain with random intercept) or "MC2R" (second order
Markov Chain with random intercept), the parametric adjusted fit is provided and
the user can set add.unadjusted=TRUE to provide the unadjusted fitted curves.
The option which=6 is used only if the random intercept is present (models
ending in "R") and provides the individual mean profile plots.
No return value, called for side effects (generating plots).
signature(x="ANY", y="ANY")Generic function.
signature(x="bild", y="missing")Plot diagnostics for bild object.
library(bild) data(locust) # It takes a very long time to run str(locust) # dependence="MC2R" Integ <- bild::bildIntegrate(li=-2.5, ls=2.5, lig=-2.5, lsg=2.5) locust2r_feed1 <- bild::bild(move~(time+I(time^2))*sex, data=locust, subSET=feed=="1", aggregate=sex, dependence="MC2R", integrate=Integ) summary(locust2r_feed1) plot(locust2r_feed1, which=5, ylab="probability of locomoting", add.unadjusted=TRUE) plot(locust2r_feed1, which=6, subSET=sex=="1", main="sex==1 & Feed=1", ident=TRUE) locust2r <- bild::bild(move~(time+I(time^2))*feed, data=locust, trace=TRUE, aggregate=feed, dependence="MC2R", integrate=Integ) par(mfrow=c(2,2)) plot(locust2r, which=1) plot(locust2r, which=2) plot(locust2r, which=3) plot(locust2r, which=4) par(mfrow=c(1,1)) plot(locust2r, which=5, ylab="probability of locomoting", main="Feed & Unfeed groups", add.unadjusted=TRUE) plot(locust2r, which=6, ylab="probability of locomoting", main="Fed & Unfed groups", ident=TRUE)library(bild) data(locust) # It takes a very long time to run str(locust) # dependence="MC2R" Integ <- bild::bildIntegrate(li=-2.5, ls=2.5, lig=-2.5, lsg=2.5) locust2r_feed1 <- bild::bild(move~(time+I(time^2))*sex, data=locust, subSET=feed=="1", aggregate=sex, dependence="MC2R", integrate=Integ) summary(locust2r_feed1) plot(locust2r_feed1, which=5, ylab="probability of locomoting", add.unadjusted=TRUE) plot(locust2r_feed1, which=6, subSET=sex=="1", main="sex==1 & Feed=1", ident=TRUE) locust2r <- bild::bild(move~(time+I(time^2))*feed, data=locust, trace=TRUE, aggregate=feed, dependence="MC2R", integrate=Integ) par(mfrow=c(2,2)) plot(locust2r, which=1) plot(locust2r, which=2) plot(locust2r, which=3) plot(locust2r, which=4) par(mfrow=c(1,1)) plot(locust2r, which=5, ylab="probability of locomoting", main="Feed & Unfeed groups", add.unadjusted=TRUE) plot(locust2r, which=6, ylab="probability of locomoting", main="Fed & Unfed groups", ident=TRUE)
bild ObjectsObtains predictions (link, response, or dynamic transition probabilities)
from a fitted bild model object for existing or new data structures.
## S3 method for class 'bild' predict( object, newdata = NULL, type = c("link", "response", "transition"), ... )## S3 method for class 'bild' predict( object, newdata = NULL, type = c("link", "response", "transition"), ... )
object |
A fitted model object of class |
newdata |
Optionally, a data frame in which to look for variables with which to predict. If omitted, the fitted linear predictors or probabilities from the original fit are returned. |
type |
The type of prediction required. Use |
... |
Additional arguments passed to or from other methods. |
A numeric vector of predicted values or probabilities matching the data rows.
library(bild) # First-order Markov dependence (MC1) data(airpollution) air1 <- bild(wheeze ~ age + smoking, data = airpollution, time = "age", aggregate = smoking, dependence = "MC1") # Standard marginal response prediction on original data pred_mar <- predict(air1, type = "response") head(pred_mar) # Dynamic transition probabilities on new data (requires y_prev1) new_data_air <- data.frame( age = c(9, 10, 11, 9, 10, 11), smoking = factor(c("0", "0", "0", "1", "1", "1")), y_prev1 = c(0, 1, 0, 1, 1, 0)) dynamic_pred_air <- predict(air1, newdata = new_data_air, type = "transition") print(cbind(new_data_air, Prob_Transition = dynamic_pred_air)) # Second-order Markov with random effects (MC2R) data(muscatine) muscatine$time1 <- c(-1, 0, 1) muscatine$time2 <- c(1, -2, 1) Integ <- bildIntegrate(lig = -3.95, lsg = 3.95) musc2r <- bild(obese ~ (time1 + time2) * sex, data = muscatine, time = "time1", start = c(1, 1, 1), dependence = "MC2R", integrate = Integ) # Dynamic transition probabilities for second-order model (requires y_prev1 and y_prev2) new_data_musc <- data.frame( time1 = c(0, 1), time2 = c(-2, 1), sex = factor(c("0", "1")), y_prev1 = c(1, 0), y_prev2 = c(0, 1)) dynamic_pred_musc <- predict(musc2r, newdata = new_data_musc, type = "transition") print(cbind(new_data_musc, Prob_Transition = dynamic_pred_musc))library(bild) # First-order Markov dependence (MC1) data(airpollution) air1 <- bild(wheeze ~ age + smoking, data = airpollution, time = "age", aggregate = smoking, dependence = "MC1") # Standard marginal response prediction on original data pred_mar <- predict(air1, type = "response") head(pred_mar) # Dynamic transition probabilities on new data (requires y_prev1) new_data_air <- data.frame( age = c(9, 10, 11, 9, 10, 11), smoking = factor(c("0", "0", "0", "1", "1", "1")), y_prev1 = c(0, 1, 0, 1, 1, 0)) dynamic_pred_air <- predict(air1, newdata = new_data_air, type = "transition") print(cbind(new_data_air, Prob_Transition = dynamic_pred_air)) # Second-order Markov with random effects (MC2R) data(muscatine) muscatine$time1 <- c(-1, 0, 1) muscatine$time2 <- c(1, -2, 1) Integ <- bildIntegrate(lig = -3.95, lsg = 3.95) musc2r <- bild(obese ~ (time1 + time2) * sex, data = muscatine, time = "time1", start = c(1, 1, 1), dependence = "MC2R", integrate = Integ) # Dynamic transition probabilities for second-order model (requires y_prev1 and y_prev2) new_data_musc <- data.frame( time1 = c(0, 1), time2 = c(-2, 1), sex = factor(c("0", "1")), y_prev1 = c(1, 0), y_prev2 = c(0, 1)) dynamic_pred_musc <- predict(musc2r, newdata = new_data_musc, type = "transition") print(cbind(new_data_musc, Prob_Transition = dynamic_pred_musc))
Extract conditional random effects
## S4 method for signature 'bild' randeff(object)## S4 method for signature 'bild' randeff(object)
object |
an object of class |
A data frame containing the random effects estimates, if the model contains random effects. Otherwise, it issues a warning.
show displays a brief summary of a fitted bild
model object, including the function call, the number of profiles used
in the fit, the number of estimated coefficients, the maximized log-likelihood,
and any convergence message.
## S4 method for signature 'bild' show(object)## S4 method for signature 'bild' show(object)
object |
An object of class |
No return value, called for side effects (printing to the console).
Summary method for class bild. Computes and prints
summary statistics for a fitted bild object.
## S4 method for signature 'bild' summary(object, cov = FALSE, cor = FALSE)## S4 method for signature 'bild' summary(object, cov = FALSE, cor = FALSE)
object |
an object of class |
cov |
logical. If TRUE, prints the covariance matrix of coefficients. |
cor |
logical. If TRUE, prints the correlation matrix of coefficients. |
Returns the summary object (invisibly).
Summary of bild objects. Extracted from a bild object,
it contains values meant for printing by the show method.
coefficientsMatrix. Estimated parameters.
seMatrix. Standard errors of estimated parameters.
covarianceMatrix. Covariance of estimated parameters.
correlationMatrix. Correlation of estimated parameters.
log.likelihoodNumeric. The value of the log likelihood.
messageInteger. Information returned by the optimizer.
n.casesNumeric. Number of individual profiles used in the optimization procedure.
ni.casesNumeric. Number of individual profiles in the dataset.
aicNumeric. The Akaike information criterion.
callLanguage. The call that generated the bild object.
bild object into a tibbleTidy a bild object into a tibble
## S3 method for class 'bild' tidy(x, conf.int = FALSE, conf.level = 0.95, ...)## S3 method for class 'bild' tidy(x, conf.int = FALSE, conf.level = 0.95, ...)
x |
A fitted model object of class |
conf.int |
Logical. Whether or not to include a confidence interval
in the tidied output. Defaults to |
conf.level |
The confidence level to use for the confidence interval
if |
... |
Additional arguments. Not used. |
For parameters estimated on the log-scale (such as dependence parameters
log.psi1, log.psi2) and the random effect variance parameter
omega, tidy.bild automatically transforms the estimates to their
natural scale (psi1, psi2, sigma2) via the exponential
function. Consequently, their standard errors are adjusted using the Delta method,
and confidence intervals are computed accordingly.
A tibble::tibble containing columns: term, estimate, std.error,
statistic, p.value, conf.low, conf.high.
library(bild) library(generics) data(airpollution) air1R <- bild::bild(wheeze ~ age + smoking, data = airpollution, time = "age", aggregate = smoking, dependence = "MC1R") tidy(air1R, conf.int = TRUE)library(bild) library(generics) data(airpollution) air1R <- bild::bild(wheeze ~ age + smoking, data = airpollution, time = "age", aggregate = smoking, dependence = "MC1R") tidy(air1R, conf.int = TRUE)
Extract variance estimates of random effects (wrapper)
## S4 method for signature 'bild' vareff(object)## S4 method for signature 'bild' vareff(object)
object |
an object of class |
A data frame containing the variance estimate.