
Last chance! 50% off unlimited learning
Sale ends in
This function generates a posterior density sample for a semiparametric linear mixed model using a Dirichlet process or a Mixture of Dirichlet process prior for the distribution of the random effects.
DPlmm(fixed,random,prior,mcmc,state,status,
data=sys.frame(sys.parent()),na.action=na.fail)
a two-sided linear formula object describing the
fixed-effects part of the model, with the response on the
left of a ~
operator and the terms, separated by +
operators, on the right.
a one-sided formula of the form ~z1+...+zn | g
, with
z1+...+zn
specifying the model for the random effects and
g
the grouping variable. The random effects formula will be
repeated for all levels of grouping.
a list giving the prior information. The list include the following
parameter: a0
and b0
giving the hyperparameters for
prior distribution of the precision parameter of the Dirichlet process
prior, alpha
giving the value of the precision parameter (it
must be specified if a0
and b0
are missing, see details
below), nu0
and Tinv
giving the hyperparameters of the
inverted Wishart prior distribution for the scale matrix of the normal
baseline distribution, sigma
giving the value of the covariance
matrix of the centering distribution (it must be specified if
nu0
and tinv
are missing),
mub
and Sb
giving the hyperparameters
of the normal prior distribution for the mean of the normal
baseline distribution, mu
giving the value of the mean of the
centering distribution (it must be specified if
mub
and Sb
are missing),
beta0
and Sbeta0
giving the
hyperparameters of the normal prior distribution for the fixed effects
(must be specified only if fixed effects are considered in the model)
and, tau1
and tau2
giving the hyperparameters for the
prior distribution of the error variance.
a list giving the MCMC parameters. The list must include
the following integers: nburn
giving the number of burn-in
scans, nskip
giving the thinning interval, nsave
giving
the total number of scans to be saved, and ndisplay
giving
the number of saved scans to be displayed on screen (the function reports
on the screen when every ndisplay
iterations have been carried
out).
a list giving the current value of the parameters. This list is used if the current analysis is the continuation of a previous analysis.
a logical variable indicating whether this run is new (TRUE
) or the
continuation of a previous analysis (FALSE
). In the latter case
the current value of the parameters must be specified in the
object state
.
data frame.
a function that indicates what should happen when the data
contain NA
s. The default action (na.fail
) causes
DPlmm
to print an error message and terminate if there are any
incomplete observations.
An object of class DPlmm
representing the linear
mixed-effects model fit. Generic functions such as print
, plot
,
summary
, and anova
have methods to show the results of the fit.
The results include betaR
, betaF
, sigma2e
,
mu
, the elements of Sigma
, alpha
, and the
number of clusters.
The function DPrandom
can be used to extract the posterior mean of the
random effects.
The list state
in the output object contains the current value of the parameters
necessary to restart the analysis. If you want to specify different starting values
to run multiple chains set status=TRUE
and create the list state based on
this starting values. In this case the list state
must include the following objects:
an integer giving the number of clusters.
giving the value of the precision parameter
a matrix of dimension (nsubjects)*(nrandom effects) giving the value of the random effects for each subject.
a matrix of dimension (nsubjects)*(nrandom effects) giving the value of the random
effects for each clusters (only the first ncluster
are considered to start the chain).
an interger vector defining to which of the ncluster
clusters each subject belongs.
giving the value of the fixed effects.
giving the mean of the normal baseline distributions.
giving the variance matrix of the normal baseline distributions.
giving the error variance.
This generic function fits a linear mixed-effects model (Verbeke
and Molenberghs, 2000):
where,
Note that the inverted-Wishart prior is parametrized such that
The precision or total mass parameter, DP
prior
can be considered as random, having a gamma
distribution,
The computational implementation of the model is based on the marginalization of
the DP
and on the use of MCMC methods for conjugate priors (Escobar, 1994;
Escobar and West, 1998). The
Escobar, M.D. (1994) Estimating Normal Means with a Dirichlet Process Prior, Journal of the American Statistical Association, 89: 268-277.
Escobar, M.D. and West, M. (1995) Bayesian Density Estimation and Inference Using Mixtures. Journal of the American Statistical Association, 90: 577-588.
Escobar, M.D. and West, M. (1998) Computing Bayesian Nonparametric Hierarchical Models, in Practical Nonparametric and Semiparametric Bayesian Statistics, eds: D. Dey, P. Muller, D. Sinha, New York: Springer-Verlag, pp. 1-22.
Muliere, P. and Tardella, L. (1998) Approximating distributions of random functionals of Ferguson-Dirichlet priors. The Canadian Journal of Statistics, 26(2): 283-297.
Verbeke, G. and Molenberghs, G. (2000). Linear mixed models for longitudinal data, New York: Springer-Verlag.
DPrandom
,
DPglmm
, DPolmm
,
DPMlmm
, DPMglmm
, DPMolmm
,
PTlmm
, PTglmm
, PTolmm
# NOT RUN {
# School Girls Data Example
data(schoolgirls)
attach(schoolgirls)
# Prior information
prior<-list(alpha=1,nu0=4.01,tau1=0.01,tau2=0.01,
tinv=diag(10,2),mub=rep(0,2),Sb=diag(1000,2))
# Initial state
state <- NULL
# MCMC parameters
nburn<-5000
nsave<-10000
nskip<-20
ndisplay<-1000
mcmc <- list(nburn=nburn,nsave=nsave,nskip=nskip,ndisplay=ndisplay)
# Fit the model: First run
fit1<-DPlmm(fixed=height~1,random=~age|child,prior=prior,mcmc=mcmc,
state=state,status=TRUE)
fit1
# Fit the model: Continuation
state<-fit1$state
fit2<-DPlmm(fixed=height~1,random=~age|child,prior=prior,mcmc=mcmc,
state=state,status=FALSE)
fit2
# Summary with HPD and Credibility intervals
summary(fit2)
summary(fit2,hpd=FALSE)
# Plot model parameters
# (to see the plots gradually set ask=TRUE)
plot(fit2,ask=FALSE)
plot(fit2,ask=FALSE,nfigr=2,nfigc=2)
# Plot an specific model parameter
# (to see the plots gradually set ask=TRUE)
plot(fit2,ask=FALSE,nfigr=1,nfigc=2,param="sigma-(Intercept)")
plot(fit2,ask=FALSE,nfigr=1,nfigc=2,param="ncluster")
# }
Run the code above in your browser using DataLab