gamm(mgcv)
gamm()所属R语言包:mgcv
Generalized Additive Mixed Models
广义添加剂混合模型
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Fits the specified generalized additive mixed model (GAMM) to data, by a call to lme in the normal errors identity link case, or by a call to gammPQL (a modification of glmmPQL from the MASS library) otherwise. In the latter case estimates are only approximately MLEs. The routine is typically slower than gam, and not quite as numerically robust.
符合指定的广义添加剂混合数据模型(GAMM),由调用lme在正常的错误标识链接的情况下,或通过调用gammPQL(修改glmmPQL MASS库),否则。在后一种情况下,估计只有约的MLE。例程通常是慢比gam,并不像数字强劲。
To use lme4 in place of nlme as the underlying fitting engine, see gamm4 from package gamm4.
使用lme4代替nlme作为底层装修引擎,看到gamm4包gamm4的。
Smooths are specified as in a call to gam as part of the fixed effects model formula, but the wiggly components of the smooth are treated as random effects. The random effects structures and correlation structures availabale for lme are used to specify other random effects and correlations.
平滑指定在调用gam的固定效应模型公式的一部分,但蠕动组件的顺利处理为随机效应。随机效应的结构和相关结构availabalelme用于指定其他随机效应和相关性。
It is assumed that the random effects and correlation structures are employed primarily to model residual correlation in the data and that the prime interest is in inference about the terms in the fixed effects model formula including the smooths. For this reason the routine calculates a posterior covariance matrix for the coefficients of all the terms in the fixed effects formula, including the smooths.
假设随机效应和相关结构,就业主要在数据模型残余相关和最优惠利率是固定效应模型公式包括的平滑推理。出于这个原因,常规计算后的协方差矩阵为固定效应公式中的所有条款,包括了平滑系数。
To use this function effectively it helps to be quite familiar with the use of gam and lme.
要使用此功能,有效地帮助是相当熟悉的与gam和lme使用。
用法----------Usage----------
gamm(formula,random=NULL,correlation=NULL,family=gaussian(),
data=list(),weights=NULL,subset=NULL,na.action,knots=NULL,
control=list(niterEM=0,optimMethod="L-BFGS-B"),
niterPQL=20,verbosePQL=TRUE,method="ML",...)
参数----------Arguments----------
参数:formula
A GAM formula (see also formula.gam and gam.models). This is like the formula for a glm except that smooth terms (s and te) can be added to the right hand side of the formula. Note that ids for smooths and fixed smoothing parameters are not supported.
一个自由亚齐运动公式(又见formula.gam和gam.models)。这就好比是除了顺利条款glm公式(s和te)可以添加到右边的公式。注意,id的平滑和固定平滑参数不支持。
参数:random
The (optional) random effects structure as specified in a call to lme: only the list form is allowed, to facilitate manipulation of the random effects structure within gamm in order to deal with smooth terms. See example below.
(可选)随机效应结构作为指定在调用lme:只有list形式是允许的,随机效应的结构,以便在gamm操纵为了顺利处理条款。见下面的例子。
参数:correlation
An optional corStruct object (see corClasses) as used to define correlation structures in lme. Any grouping factors in the formula for this object are assumed to be nested within any random effect grouping factors, without the need to make this explicit in the formula (this is slightly different to the behaviour of lme). This is a GEE approach to correlation in the generalized case. See examples below.
一个可选的corStruct对象(见corClasses)用来定义在lme相关结构。假设嵌套在任何随机效应分组因素,而不需要使这个明确的公式中的(这是稍有不同的行为lme),在此对象的公式任何分组因素。这是在广义的情况下,GEE方法相关。见下面的例子。
参数:family
A family as used in a call to glm or gam. The default gaussian with identity link causes gamm to fit by a direct call to lme procided there is no offset term, otherwise gammPQL is used.
一个family在通话中使用glm或gam。默认gaussian与身份的链接导致gamm适合直接调用lmeprocided有没有失调项,否则gammPQL使用。
参数:data
A data frame or list containing the model response variable and covariates required by the formula. By default the variables are taken from environment(formula), typically the environment from which gamm is called.
数据框列表,其中包含模型响应变量和协变量所需的公式。默认情况下,变量environment(formula),通常是从哪个gamm被称为环境。
参数:weights
In the generalized case, weights with the same meaning as glm weights. An lme type weights argument may only be used in the identity link gaussian case, with no offset (see documentation for lme for details of how to use such an argument).
在广义的情况下,具有相同的含义glm重的重量。 lme类型的权重参数可能只被用于标识链接高斯情况下,无偏移(见文档)lme详细介绍如何使用这种说法。
参数:subset
an optional vector specifying a subset of observations to be used in the fitting process.
一个可选的向量指定要在装修过程中使用的观测的子集。
参数:na.action
a function which indicates what should happen when the data contain "NA"s. The default is set by the "na.action" setting of "options", and is "na.fail" if that is unset. The “factory-fresh” default is "na.omit".
一个函数,它表示数据时,包含“NA的,应该发生什么。由的“na.action的”选项“设置,默认设置是”na.fail“如果没有设置。的“新鲜工厂”默认na.omit“。
参数:knots
this is an optional list containing user specified knot values to be used for basis construction. Different terms can use different numbers of knots, unless they share a covariate.
这是一个可选列表,其中包含用户指定的结值被用于基础建设。不同的条件,可以使用不同数量的结,除非它们共享一个协。
参数:control
A list of fit control parameters for lme to replace the defaults returned by lmeControl. Note the setting for the number of EM iterations used by lme: smooths are set up using custom pdMat classes, which are currently not supported by the EM iteration code. If you supply a list of control values, it is advisable to include niterEM=0, as well, and only increase from 0 if you want to perturb the starting values used in model fitting (usually to worse values!). The optimMethod option is only used if your version of R does not have the nlminb optimizer function.
一个lme取代lmeControl返回的默认列表合适的控制参数。注意:由lme使用的EM迭代的设置:平滑设置了使用自定义的pdMat类,目前不支持的EM迭代代码。如果您提供的控制值的列表,它最好包括niterEM=0,以及从0增加,如果你想扰动模型拟合使用的值(通常是雪上加霜值!)开始。 optimMethod选项仅用于如果您的R版本不具备的nlminb优化功能。
参数:niterPQL
Maximum number of PQL iterations (if any).
PQL迭代的最大数目(如有)。
参数:verbosePQL
Should PQL report its progress as it goes along?
PQL应报告其进展情况,随之而来的吗?
参数:method
Which of "ML" or "REML" to use in the Gaussian additive mixed model case when lme is called directly. Ignored in the generalized case (or if the model has an offset), in which case gammPQL is used.
"ML"或"REML"使用高斯混合模型的情况下,当lme被称为直接添加剂。在广义的情况下忽略(或模型的偏移量),在这种情况下,gammPQL使用。
参数:...
further arguments for passing on e.g. to lme
上,例如通过进一步的参数lme
Details
详情----------Details----------
The Bayesian model of spline smoothing introduced by Wahba (1983) and Silverman (1985) opens up the possibility of estimating the degree of smoothness of terms in a generalized additive model as variances of the wiggly components of the smooth terms treated as random effects. Several authors have recognised this (see Wang 1998; Ruppert, Wand and Carroll, 2003) and in the normal errors, identity link case estimation can be performed using general linear mixed effects modelling software such as lme. In the generalized case only approximate inference is so far available, for example using the Penalized Quasi-Likelihood approach of Breslow and Clayton (1993) as implemented in glmmPQL by Venables and Ripley (2002). One advantage of this approach is that it allows correlated errors to be dealt with via random effects or the correlation structures available in the nlme library (using correlation structures beyond the strictly additive case amounts to using a GEE approach to fitting).
Wahba(1983年)和Silverman(1985)所提出的贝叶斯模型的样条平滑开辟了估计广义相加模型在蠕动组件视为随机效应的顺利条款的差异方面的平滑程度的可能性。几位作者都承认(见王1998年Ruppert公司,魔杖和Carroll,2003),在正常的错误,标识链接的情况下估计可使用一般线性混合效应建模软件,如lme。仅在广义的情况下近似推理是迄今为止,例如使用的处罚拟似然方法布瑞斯罗夫和Clayton(1993)实施glmmPQL维纳布尔斯和Ripley(2002)。这种方法的优点之一是它允许相关的错误,要通过随机效应或nlme库(使用超出严格添加剂的情况下大量使用,GEE的方法来拟合相关结构)提供的相关结构与处理。
Some details of how GAMs are represented as mixed models and estimated using lme or gammPQL in gamm can be found in Wood (2004 ,2006a,b). In addition gamm obtains a posterior covariance matrix for the parameters of all the fixed effects and the smooth terms. The approach is similar to that described in Lin & Zhang (1999) - the covariance matrix of the data (or pseudodata in the generalized case) implied by the weights, correlation and random effects structure is obtained, based on the estimates of the parameters of these terms and this is used to obtain the posterior covariance matrix of the fixed and smooth effects.
如何GAMS表示为混合模型,并估计使用的一些细节lme或gammPQLgamm可以发现在木材(2004,2006A,B)。此外gamm获得了所有的固定效果和顺利条款参数后的协方差矩阵。在林和张(1999)所描述的 - 暗示的重量数据(或伪数据在广义的情况下)的协方差矩阵的方法是类似的,相关性和随机效应结构参数估计的基础上得到这些条款,这是用来取得固定,顺滑的效果后的协方差矩阵。
The bases used to represent smooth terms are the same as those used in gam, although adaptive smoothing bases are not available.
代表顺利的术语使用的基地是在gam使用的相同,但不可自适应平滑基地。
In the event of lme convergence failures, consider modifying option(mgcv.vc.logrange): reducing it helps to remove indefiniteness in the likelihood, if that is the problem, but too large a reduction can force over or undersmoothing. See notExp2 for more information on this option. Failing that, you can try increasing the niterEM option in control: this will perturb the starting values used in fitting, but usually to values with lower likelihood! Note that this version of gamm works best with R 2.2.0 or above and nlme, 3.1-62 and above, since these use an improved optimizer.
在lme的收敛失败的情况下,考虑修改option(mgcv.vc.logrange):减少它有助于消除不确定性的可能性,如果是这样的问题,但减少过大,可以强制或undersmoothing。看到notExp2此选项的更多信息。做不到这一点,你可以尝试增加niterEM选项control:这将干扰开始在装修中使用的值,但通常值的可能性较低!请注意,此版本gamm最好用R 2.2.0或以上和nlme,3.1-62及以上,因为这些使用改进的优化。
值----------Value----------
Returns a list with two items:
返回两个项目列表:
参数:gam
an object of class gam, less information relating to GCV/UBRE model selection. At present this contains enough information to use predict, summary and print methods and vis.gam, but not to use e.g. the anova method function to compare models.
gam类的对象,少GCV / UBRE模式选择有关的信息。目前,这包含足够的信息来使用predictsummary和print方法和vis.gam,而不是使用如anova方法比较模型的功能。
参数:lme
the fitted model object returned by lme or gammPQL. Note that the model formulae and grouping structures may appear to be rather bizarre, because of the manner in which the GAMM is split up and the calls to lme and gammPQL are constructed.
拟合模型对象返回lme或gammPQL。注意模型公式和分组结构,可能会出现相当怪异,因为其中GAMM分裂的方式和调用lme和gammPQL构造。
警告----------WARNINGS ----------
gamm performs poorly with binary data, since it uses PQL. It is better to use gam with s(...,bs="re") terms, or gamm4.
gamm表现不佳的二进制数据,因为它使用伪似然法。这是更好地使用与gam条款s(...,bs="re")或gamm4。
gamm assumes that you know what you are doing! For example, unlike glmmPQL from MASS it will return the complete lme object from the working model at convergence of the PQL iteration, including the 'log likelihood', even though this is not the likelihood of the fitted GAMM.
gamm假设你知道你在做什么!例如,不像glmmPQLMASS它会返回完整的lme对象从收敛的PQL迭代的工作模式,包括“日志的可能性”,尽管这不是可能性安装GAMM。
The routine will be very slow and memory intensive if correlation structures are used for the very large groups of data. e.g. attempting to run the spatial example in the examples section with many 1000's of data is definitely not recommended: often the correlations should only apply within clusters that can be defined by a grouping factor, and provided these clusters do not get too huge then fitting is usually possible.
程序将是非常缓慢和内存密集的数据非常大的群体,如果相关结构。例如试图来运行例子一节中许多千数据的的空间的例子是绝对不建议:经常的相互关系应该适用,可将1分组因素定义集群内,并提供这些集群不要过于庞大然后拟合是通常可能。
Models must contain at least one random effect: either a smooth with non-zero smoothing parameter, or a random effect specified in argument random.
模型必须至少包含一个随机效应:要么顺利非零平滑参数,或参数random指定一个随机的效果。
gamm is not as numerically stable as gam: an lme call will occasionally fail. See details section for suggestions, or try the "gamm4" package.
gamm是不是数值稳定gam:lme呼叫有时会失败。看到部分细节提出建议,或尝试“gamm4”包。
gamm is usually much slower than gam, and on some platforms you may need to increase the memory available to R in order to use it with large data sets (see mem.limits).
gamm通常是慢得多比gam,在某些平台上,你可能需要增加的可用内存为R,以使用大型数据集(见mem.limits)。
Note that the weights returned in the fitted GAM object are dummy, and not those used by the PQL iteration: this makes partial residual plots look odd.
请注意,在装的GAM对象返回的重量是假人,而不是那些使用由PQL迭代:这使得部分残差图看起来很奇怪。
Note that the gam object part of the returned object is not complete in the sense of having all the elements defined in gamObject and does not inherit from glm: hence e.g. multi-model anova calls will not work.
请注意,gam对象的一部分返回的对象是不完整的所有元素定义在gamObject“不继承glm感:因此如多模型anova电话将无法正常工作。
The parameterization used for the smoothing parameters in gamm, bounds them above and below by an effective infinity and effective zero. See notExp2 for details of how to change this.
gamm,平滑参数的参数限定有效的无限性和有效的零的上方和下方。看到notExp2如何改变这种细节。
Linked smoothing parameters and adaptive smoothing are not supported.
不支持链接的平滑参数和自适应平滑。
作者(S)----------Author(s)----------
Simon N. Wood <a href="mailto:simon.wood@r-project.org">simon.wood@r-project.org</a>
参考文献----------References----------
mixed models. Journal of the American Statistical Association 88, 9-25.
splines. JRSSB. 55(2):381-400
Cambridge
JRSSB 47:1-52
with S. Fourth edition. Springer.
JRSSB 45:133-150
generalized additive models. Journal of the American Statistical Association. 99:673-686
generalized additive mixed models. Biometrics 62(4):1025-1036
and Hall/CRC Press.
参见----------See Also----------
magic for an alternative for correlated data, te, s, predict.gam, plot.gam, summary.gam, negbin, vis.gam,pdTens, gamm4 ( http://cran.r-project.org/package=gamm4)
magic替代的相关数据,te,s,predict.gam,plot.gam,summary.gam,negbin,< x>,vis.gam,pdTens(http://cran.r-project.org/package=gamm4)
举例----------Examples----------
library(mgcv)
## simple examples using gamm as alternative to gam[#简单的例子,使用替代GAM GAMM]
set.seed(0)
dat <- gamSim(1,n=400,scale=2)
b <- gamm(y~s(x0)+s(x1)+s(x2)+s(x3),data=dat)
plot(b$gam,pages=1)
summary(b$lme) # details of underlying lme fit[细节的背后LME适合]
summary(b$gam) # gam style summary of fitted model[GAM拟合模型的风格总结]
anova(b$gam)
gam.check(b$gam) # simple checking plots[简单的检查图]
b <- gamm(y~te(x0,x1)+s(x2)+s(x3),data=dat)
op <- par(mfrow=c(2,2))
plot(b$gam)
par(op)
rm(dat)
## Add a factor to the linear predictor, to be modelled as random[#添加一个线性预测的因素,被视为随机建模]
dat <- gamSim(6,n=400,scale=.2,dist="poisson")
b2<-gamm(y~s(x0)+s(x1)+s(x2)+s(x3),family=poisson,
data=dat,random=list(fac=~1))
plot(b2$gam,pages=1)
fac <- dat$fac
rm(dat)
vis.gam(b2$gam)
## now an example with autocorrelated errors....[#现在与自我相关的错误的一个例子....]
n <- 400;sig <- 2
x <- 0n-1)/(n-1)
f <- 0.2*x^11*(10*(1-x))^6+10*(10*x)^3*(1-x)^10
e <- rnorm(n,0,sig)
for (i in 2:n) e[i] <- 0.6*e[i-1] + e[i]
y <- f + e
op <- par(mfrow=c(2,2))
b <- gamm(y~s(x,k=20),correlation=corAR1())
plot(b$gam);lines(x,f-mean(f),col=2)
b <- gamm(y~s(x,k=20))
plot(b$gam);lines(x,f-mean(f),col=2)
b <- gam(y~s(x,k=20))
plot(b);lines(x,f-mean(f),col=2)
## more complicated autocorrelation example - AR errors[#更复杂的自相关的例子 - AR的错误]
## only within groups defined by `fac'[#仅在因子定义组“]
e <- rnorm(n,0,sig)
for (i in 2:n) e[i] <- 0.6*e[i-1]*(fac[i-1]==fac[i]) + e[i]
y <- f + e
b <- gamm(y~s(x,k=20),correlation=corAR1(form=~1|fac))
plot(b$gam);lines(x,f-mean(f),col=2)
par(op)
## more complex situation with nested random effects and within[#更复杂的情况下,嵌套随机效应和内]
## group correlation [#组相关]
set.seed(0)
n.g <- 10
n<-n.g*10*4
## simulate smooth part...[#模拟光滑的一部分...]
dat <- gamSim(1,n=n,scale=2)
f <- dat$f
## simulate nested random effects....[#模拟嵌套的随机效果....]
fa <- as.factor(rep(1:10,rep(4*n.g,10)))
ra <- rep(rnorm(10),rep(4*n.g,10))
fb <- as.factor(rep(rep(1:4,rep(n.g,4)),10))
rb <- rep(rnorm(4),rep(n.g,4))
for (i in 1:9) rb <- c(rb,rep(rnorm(4),rep(n.g,4)))
## simulate auto-correlated errors within groups[#模拟组内汽车相关的错误]
e<-array(0,0)
for (i in 1:40) {
eg <- rnorm(n.g, 0, sig)
for (j in 2:n.g) eg[j] <- eg[j-1]*0.6+ eg[j]
e<-c(e,eg)
}
dat$y <- f + ra + rb + e
dat$fa <- fa;dat$fb <- fb
## fit model .... [#适合模型....]
b <- gamm(y~s(x0,bs="cr")+s(x1,bs="cr")+s(x2,bs="cr")+
s(x3,bs="cr"),data=dat,random=list(fa=~1,fb=~1),
correlation=corAR1())
plot(b$gam,pages=1)
vis.gam(b$gam)
## and a "spatial" example...[#和“空间”的例子...]
library(nlme);set.seed(1);n <- 200
dat <- gamSim(2,n=n,scale=0) ## standard example[#标准的例子]
attach(dat)
old.par<-par(mfrow=c(2,2))
contour(truth$x,truth$z,truth$f) ## true function[#真正的功能]
f <- data$f ## true expected response[#真正的预期响应]
## Now simulate correlated errors...[#现在模拟相关的错误...]
cstr <- corGaus(.1,form = ~x+z)
cstr <- Initialize(cstr,data.frame(x=data$x,z=data$z))
V <- corMatrix(cstr) ## correlation matrix for data[#数据的相关矩阵]
Cv <- chol(V)
e <- t(Cv) %*% rnorm(n)*0.05 # correlated errors[相关误差]
## next add correlated simulated errors to expected values[#未来的预期值增加相关的模拟误差]
data$y <- f + e ## ... to produce response[#...产生反应]
b<- gamm(y~s(x,z,k=50),correlation=corGaus(.1,form=~x+z),
data=data)
plot(b$gam) # gamm fit accounting for correlation[GAMM为相关合适的会计]
# overfits when correlation ignored..... [overfits相关忽略.....]
b1 <- gamm(y~s(x,z,k=50),data=data);plot(b1$gam)
b2 <- gam(y~s(x,z,k=50),data=data);plot(b2)
par(old.par)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|