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库),否则。在后者的情况下,估计仅约为最大似然估计。该例程是典型的慢于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的固定效应模型公式中的一部分,但蠕动的组件的光滑被视为随机效应。随机效应的结构和相关结构availabale lme是用来指定随机效应和相关性。
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.
一个的GAM公式(formula.gam和gam.models“)。这是像公式的glm除了光滑条款(s和te)可以添加到右手边的公式。需要注意的是ids的平滑和固定的平滑参数不支持。
参数: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.
Afamily用于调用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合适的控制参数列表。注意使用lmeEM迭代的数量设置为:平滑设置了使用自定义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).
沃赫拜(1983)和Silverman(1985)介绍了样条平滑的贝叶斯模型打开了估计的术语在广义相加模型作为方差的蠕动的组件视为随机效应的顺利条款的平滑程度的可能性。一些作者已经认识到这一点(见王1998年,鲁珀特,魔杖和Carroll,2003),在正常的错误,身份连接的情况估计可使用一般线性混合效应建模软件如lme。仅在广义的情况下的近似推理是迄今为止,例如使用和Clayton(1993),布瑞斯罗夫受到处罚的拟似然方法中实现glmmPQL维纳布尔斯以及雷普利(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年,2006年,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的模型选择。目前,这包含足够的信息来使用predict,summary和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表现不佳的二进制数据,因为它使用PQL。这是更好地使用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.
这个过程将是非常缓慢的,如果相关性非常大的群体的数据结构用于内存密集型。例如试图向运行的空间例如在示例一节与许多1000的数据是绝对不推荐的:经常的相关性仅适用于内,可以被定义一个分组因素的聚类,提供这些聚类别太过于庞大然后装修是通常可能。
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.
不支持链接的平滑参数和自适应平滑。
(作者)----------Author(s)----------
Simon N. Wood [email protected]
参考文献----------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,,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
b
plot(b$gam,pages=1)
summary(b$lme) # details of underlying lme fit[的相关LME适合的详细信息]
summary(b$gam) # gam style summary of fitted model[自由亚齐运动风格的总结拟合模型]
anova(b$gam)
gam.check(b$gam) # simple checking plots[简单的检查图]
b
op
plot(b$gam)
par(op)
rm(dat)
## Add a factor to the linear predictor, to be modelled as random[#添加一个因素的线性预测,建模为随机]
dat
b2
data=dat,random=list(fac=~1))
plot(b2$gam,pages=1)
fac
rm(dat)
vis.gam(b2$gam)
## now an example with autocorrelated errors....[#现在与自我相关的错误的一个例子。...]
n
x
n-1)/(n-1)
f
e
for (i in 2:n) e[i]
y
op
b
plot(b$gam);lines(x,f-mean(f),col=2)
b
plot(b$gam);lines(x,f-mean(f),col=2)
b
plot(b);lines(x,f-mean(f),col=2)
## more complicated autocorrelation example - AR errors[#更复杂的自相关的例子 - AR错误]
## only within groups defined by `fac'[#外交事务委员会所定义的组内“]
e
for (i in 2:n) e[i]
y
b
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
n
## simulate smooth part...[模拟平滑部分...]
dat
f
## simulate nested random effects....[#模拟嵌套的随机效应......]
fa
ra
fb
rb
for (i in 1:9) rb
## simulate auto-correlated errors within groups[#模拟自相关组内的错误]
e
for (i in 1:40) {
eg
for (j in 2:n.g) eg[j]
e
}
dat$y
dat$fa
## fit model .... [#拟合模型......]
b
s(x3,bs="cr"),data=dat,random=list(fa=~1,fb=~1),
correlation=corAR1())
plot(b$gam,pages=1)
summary(b$gam)
vis.gam(b$gam)
## and a "spatial" example...[#和“空间”的例子...]
library(nlme);set.seed(1);n
dat <- gamSim(2,n=n,scale=0) ## standard example[#标准的例子]
attach(dat)
old.par
contour(truth$x,truth$z,truth$f) ## true function[#真正的功能]
f <- data$f ## true expected response[#真正预期的响应]
## Now simulate correlated errors...[#模拟相关的错误...]
cstr
cstr
V <- corMatrix(cstr) ## correlation matrix for data[#相关矩阵的数据]
Cv
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
data=data)
plot(b$gam) # gamm fit accounting for correlation[GAMM适合会计的相关性]
# overfits when correlation ignored..... [overfits时,相关忽略.....]
b1
b2
par(old.par)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。