magic(mgcv)
magic()所属R语言包:mgcv
Stable Multiple Smoothing Parameter Estimation by GCV or UBRE
平滑稳定的多参数估计GCV或UBRE
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Function to efficiently estimate smoothing parameters in generalized ridge regression problems with multiple (quadratic) penalties, by GCV or UBRE. The function uses Newton's method in multi-dimensions, backed up by steepest descent to iteratively adjust the smoothing parameters for each penalty (one penalty may have a smoothing parameter fixed at 1).
功能能够有效地估计在广义岭回归问题多(二次)处罚GCV或UBRE,平滑参数。该函数使用牛顿的方法,多层面,支持速下降,反复调整平滑参数(一个点球可能有一个平滑参数固定为1)为每个罚款。
For maximal numerical stability the method is based on orthogonal decomposition methods, and attempts to deal with numerical rank deficiency gracefully using a truncated singular value decomposition approach.
为最大数值稳定的方法是基于正交分解的方法,并尝试处理正常使用截断奇异值分解方法与数值排名缺乏。
用法----------Usage----------
magic(y,X,sp,S,off,L=NULL,lsp0=NULL,rank=NULL,H=NULL,C=NULL,
w=NULL,gamma=1,scale=1,gcv=TRUE,ridge.parameter=NULL,
control=list(maxit=50,tol=1e-6,step.half=25,
rank.tol=.Machine$double.eps^0.5),extra.rss=0,n.score=length(y))
参数----------Arguments----------
参数:y
is the response data vector.
是响应数据向量。
参数:X
is the model matrix.
是模型矩阵。
参数:sp
is the array of smoothing parameters. The vector L%*%log(sp) + lsp0 contains the logs of the smoothing parameters that actually multiply the penalty matrices stored in S (L is taken as the identity if NULL). Any sp values that are negative are autoinitialized, otherwise they are taken as supplying starting values. A supplied starting value will be reset to a default starting value if the gradient of the GCV/UBRE score is too small at the supplied value.
是平滑参数的数组。向量L%*%log(sp) + lsp0包含平滑参数实际上乘以罚款矩阵存储在日志S(L身份NULL)。 autoinitialized任何sp的值是负的,否则他们提供初始值。提供的值将重置为默认起始值,如果GCV / UBRE得分的梯度是在所提供的值太小。
参数:S
is a list of of penalty matrices. S[[i]] is the ith penalty matrix, but note that it is not stored as a full matrix, but rather as the smallest square matrix including all the non-zero elements of the penalty matrix. Element 1,1 of S[[i]] occupies element off[i], off[i] of the ith penalty matrix. Each S[[i]] must be positive semi-definite. Set to list() if there are no smoothing parameters to be estimated.
是罚款矩阵列表。 S[[i]]是第i罚款矩阵,但要注意,它不是作为一个完整的矩阵存储,但宁可作为最小的方阵,其中包括所有罚款矩阵的非零元素。元S[[i]] 1,1占地元素off[i],off[i]第i罚款矩阵。每个S[[i]]必须是半正定的。设置list()如果没有平滑参数估计。
参数:off
is an array indicating the first parameter in the parameter vector that is penalized by the penalty involving S[[i]].
是一个数组,指示在参数向量的第一个参数是由涉及S[[i]]的罚款处罚。
参数:L
is a matrix mapping log(sp) to the log smoothing parameters that actually multiply the penalties defined by the elemts of S. Taken as the identity, if NULL. See above under sp.
是一个矩阵映射log(sp)日志平滑参数,实际上繁殖由S的elemts定义的刑罚的。两者的身份,如果NULL。见上文下sp。
参数:lsp0
If L is not NULL this is a vector of constants in the linear transformation from log(sp) to the actual log smoothing parameters. So the logs of the smoothing parameters multiplying the S[[i]] are given by L%*%log(sp) + lsp0. Taken as 0 if NULL.
L如果非NULL这是一个从log(sp)实际日志平滑参数的线性变换的常数向量。因此,平滑乘以参数的日志S[[i]]是L%*%log(sp) + lsp0。采取为0,如果NULL。
参数:rank
is an array specifying the ranks of the penalties. This is useful, but not essential, for forming square roots of the penalty matrices.
是一个数组指定的刑罚的行列。这是有用的,但不是必需的,形成的刑罚矩阵的平方根。
参数:H
is the optional offset penalty - i.e. a penalty with a smoothing parameter fixed at 1. This is useful for allowing regularization of the estimation process, fixed smoothing penalties etc.
是可选的偏移刑罚 - 即固定在1平滑参数的罚款。这是非常有用的,允许估计过程的正规化,固定平滑的罚则等。
参数:C
is the optional matrix specifying any linear equality constraints on the fitting problem. If b is the parameter vector then the parameters are forced to satisfy Cb=0.
指定任何装修问题上的线性等式约束是可选的矩阵。如果b然后是参数向量参数被迫满足Cb=0。
参数:w
the regression weights. If this is a matrix then it is taken as being the square root of the inverse of the covariance matrix of y, specifically V_y^{-1}=w'w. If w is an array then it is taken as the diagonal of this matrix, or simply the weight for each element of y. See below for an example using this.
回归权。如果这是一个矩阵,那么它被当作是逆的协方差矩阵的y,专V_y^{-1}=w'w的平方根。如果w是一个数组,那么这个矩阵对角线,或每个y元素只是重量。见下面使用这个例子。
参数:gamma
is an inflation factor for the model degrees of freedom in the GCV or UBRE score.
在GCV的或UBRE得分的自由模型度的通胀因素。
参数:scale
is the scale parameter for use with UBRE.
是为与UBRE使用的尺度参数。
参数:gcv
should be set to TRUE if GCV is to be used, FALSE for UBRE.
应设置为TRUE如果是用于GCV的,FALSEUBRE。
参数:ridge.parameter
It is sometimes useful to apply a ridge penalty to the fitting problem, penalizing the parameters in the constrained space directly. Setting this parameter to a value greater than zero will cause such a penalty to be used, with the magnitude given by the parameter value.
它有时是有用的申请一垄刑罚的拟合问题,直接惩罚参数,在有限的空间。设置这个参数的值大于零,将导致这种惩罚要使用的参数值幅度。
参数:control
is a list of iteration control constants with the following elements:
是一个包含下列元素的迭代控制常数的列表:
maxitThe maximum number of iterations of the magic algorithm to allow.
maxitThe神奇的算法,允许迭代的最大数量。
tolThe tolerance to use in judging convergence.
tolThe容忍使用在判断收敛。
step.halfIf a trial step fails then the method tries halving it up to a maximum of step.half times.
step.halfIf试验步骤失败,则该方法尝试的减半它最多step.half倍。
rank.tolis a constant used to test for numerical rank deficiency of the problem. Basically any singular value less than rank_tol multiplied by the largest singular value of the problem is set to zero. </table>
rank.tolis一个常数用来测试问题的数值秩亏。基本上任何奇异值比rank_tol问题最大的奇异值乘以被设置为零。 </ TABLE>
参数:extra.rss
is a constant to be added to the residual sum of squares (squared norm) term in the calculation of the GCV, UBRE and scale parameter estimate. In conjuction with n.score, this is useful for certain methods for dealing with very large data sets.
是被添加到的残差平方和(平方规范)在GCV的,UBRE和尺度参数估计计算的长期不变。在用n.score一起选择,这是有用的某些方法处理非常大的数据集。
参数:n.score
number to use as the number of data in GCV/UBRE score calculation: usually the actual number of data, but there are methods for dealing with very large datasets that change this.
号码使用GCV / UBRE得分计算的数据:通常实际人数的数据,但也有具有非常大的数据集,改变这种处理方法。
Details
详情----------Details----------
The method is a computationally efficient means of applying GCV or UBRE (often approximately AIC) to the problem of smoothing parameter selection in generalized ridge regression problems of the form:
该方法计算的有效手段的应用GCV和UBRE(通常约AIC)的广义岭回归问题的形式平滑参数的选择问题:
possibly subject to constraints Cb=0. X is a design matrix, b a parameter vector, y a data vector, W a weight matrix, S_i a positive semi-definite matrix of coefficients defining the ith penalty with associated smoothing parameter theta_i, H is the positive semi-definite offset penalty matrix and C a matrix of coefficients defining any linear equality constraints on the problem. X need not be of full column rank.
可能是受约束的Cb=0。 X是一个设计矩阵,b参数向量,y数据向量,W权重矩阵,S_i半正定矩阵系数定义第i处罚相关的平滑参数theta_i,H的半正定抵消罚款矩阵和C的定义问题上的任何线性等式约束的系数矩阵。 X不必列满秩。
The theta_i are chosen to minimize either the GCV score:
theta_i选择,以尽量减少对GCV的得分:
or the UBRE score:
或UBRE得分:
where g is gamma the inflation factor for degrees of freedom (usually set to 1) and s is scale, the scale parameter. A is the hat matrix (influence matrix) for the fitting problem (i.e the matrix mapping data to fitted values). Dependence of the scores on the smoothing parameters is through A.
g是gamma自由度通货膨胀因素(通常设置为1)s是scale,尺度参数。 A是装修的问题(即矩阵映射数据拟合值)的帽子矩阵(影响矩阵)。依赖平滑参数的分数是通过A。
The method operates by Newton or steepest descent updates of the logs of the theta_i. A key aspect of the method is stable and economical calculation of the first and second derivatives of the scores w.r.t. the log smoothing parameters. Because the GCV/UBRE scores are flat w.r.t. very large or very small theta_i, it's important to get good starting parameters, and to be careful not to step into a flat region of the smoothing parameter space. For this reason the algorithm rescales any Newton step that would result in a log(theta_i) change of more than 5. Newton steps are only used if the Hessian of the GCV/UBRE is postive definite, otherwise steepest descent is used. Similarly steepest descent is used if the Newton step has to be contracted too far (indicating that the quadratic model underlying Newton is poor). All initial steepest descent steps are scaled so that their largest component is 1. However a step is calculated, it is never expanded if it is successful (to avoid flat portions of the objective), but steps are successively halved if they do not decrease the GCV/UBRE score, until they do, or the direction is deemed to have failed. (Given the smoothing parameters the optimal b parameters are easily found.)
该方法操作由牛顿或theta_i的日志最速下降更新。该方法的一个关键方面是稳定和经济的第一和第二的分数WRT衍生物的计算日志平滑参数。由于GCV / UBRE成绩平w.r.t.非常大或非常小的theta_i,它是重要的是获得良好的开端参数,要小心,不要步入平滑参数空间的平坦区域。出于这个原因,该算法重新调整任何牛顿的步骤,将导致一个log(theta_i)变化超过5。牛顿步骤仅用于如果黑森州的GCV / UBRE的是阳性明确,否则最速下降。同样使用最速下降,如果牛顿一步都有承包太多表明二次模型的基本牛顿差。所有的初始速下降步骤缩放,所以,他们最大的组成部分,是1。但计算了一步,它从来没有扩大,如果它是成功的(以避免目标的平坦部分),但先后步骤减半,如果他们不降低GCV / UBRE得分,直到他们这样做,或方向被视为都失败了。 (鉴于平滑参数的最优b参数很容易发现。)
The method is coded in C with matrix factorizations performed using LINPACK and LAPACK routines.
该方法编码C使用的LINPACK以及LAPACK例程进行矩阵分解。
值----------Value----------
The function returns a list with the following items:
该函数返回下列项目列表:
参数:b
The best fit parameters given the estimated smoothing parameters.
最合适的参数估计平滑参数。
参数:scale
the estimated (GCV) or supplied (UBRE) scale parameter.
估计(GCV)或提供(UBRE)尺度参数。
参数:score
the minimized GCV or UBRE score.
最小化的GCV的或UBRE得分。
参数:sp
an array of the estimated smoothing parameters.
估计平滑参数的数组。
参数:sp.full
an array of the smoothing parameters that actually multiply the elements of S (same as sp if L was NULL). This is exp(L%*%log(sp)).
实际上繁殖S元素的平滑参数的数组(sp相同如果L是NULL)。这exp(L%*%log(sp))。
参数:rV
a factored form of the parameter covariance matrix. The (Bayesian) covariance matrix of the parametes b is given by rV%*%t(rV)*scale.
一个参数的协方差矩阵的分解形式。该指标的影响(贝叶斯)的协方差矩阵brV%*%t(rV)*scale。
参数:gcv.info
is a list of information about the performance of the method with the following elements:
是一个性能的方法与下列因素有关的资料的列表:
full.rankThe apparent rank of the problem: number of parameters less number of equality constraints.
full.rankThe排名明显的问题:等式约束的数量减少参数的数量。
rankThe estimated actual rank of the problem (at the final iteration of the method).
rankThe估计实际问题(在最后一次迭代的方法)的排名。
fully.convergedis TRUE if the method converged by satisfying the convergence criteria, and FALSE if it coverged by failing to decrease the score along the search direction.
fully.convergedisTRUE如果该方法融合满足收敛准则,FALSE如果它不沿搜索方向,以减少得分融合型。
hess.pos.defis TRUE if the hessian of the UBRE or GCV score was positive definite at convergence.
hess.pos.defisTRUE如果麻袋的UBRE或GCV得分是积极趋同明确。
iteris the number of Newton/Steepest descent iterations taken.
iteris牛顿/最速下降迭代。
score.callsis the number of times that the GCV/UBRE score had to be evaluated.
score.callsis GCV / UBRE得分进行评估的时间。
rms.gradis the root mean square of the gradient of the UBRE/GCV score w.r.t. the smoothing parameters.
rms.gradis根意味着平方米的UBRE / GCV得分WRT梯度平滑参数。
Note that some further useful quantities can be obtained using magic.post.proc.
注意使用magic.post.proc可以得到进一步的一些有用的数量。
作者(S)----------Author(s)----------
Simon N. Wood <a href="mailto:simon.wood@r-project.org">simon.wood@r-project.org</a>
参考文献----------References----------
generalized additive models. J. Amer. Statist. Ass. 99:673-686
参见----------See Also----------
magic.post.proc, mgcv,gam
magic.post.proc,mgcv,gam
举例----------Examples----------
## Use `magic' for a standard additive model fit ... [#使用标准的添加剂模型拟合的魔...]
library(mgcv)
set.seed(1);n <- 400;sig <- 2
dat <- gamSim(1,n=n,scale=sig)
## set up additive model[#成立加法模型]
G <- gam(y~s(x0)+s(x1)+s(x2)+s(x3),fit=FALSE,data=dat)
## fit using magic[#适合使用魔法]
mgfit <- magic(G$y,G$X,G$sp,G$S,G$off,rank=G$rank,C=G$C)
## and fit using gam as consistency check[#适合使用GAM一致性检查]
b <- gam(G=G)
mgfit$sp;b$sp # compare smoothing parameter estimates[比较平滑的参数估计]
edf <- magic.post.proc(G$X,mgfit,G$w)$edf # get e.d.f. per param[获得e.d.f.每个参数]
range(edf-b$edf) # compare[比较]
## constrain first two smooths to have identical smoothing parameters[#限制前两种平滑有相同的平滑参数]
L <- diag(3);L <- rbind(L[1,],L)
mgfit <- magic(G$y,G$X,rep(-1,3),G$S,G$off,L=L,rank=G$rank,C=G$C)
## Now a correlated data example ... [#现在相关的数据的例子...]
library(nlme)
## simulate truth[#模拟真相]
set.seed(1);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
## produce scaled covariance matrix for AR1 errors...[#生产规模的协方差矩阵AR1的错误...]
V <- corMatrix(Initialize(corAR1(.6),data.frame(x=x)))
Cv <- chol(V) # t(Cv)%*%Cv=V[T(CV)%*%CV = V]
## Simulate AR1 errors ...[#模拟AR1的错误...]
e <- t(Cv)%*%rnorm(n,0,sig) # so cov(e) = V * sig^2[所以COV(E)= V * SIG ^ 2]
## Observe truth + AR1 errors[#观察真理+ AR1的错误。]
y <- f + e
## GAM ignoring correlation[#自由亚齐运动无视相关]
par(mfrow=c(1,2))
b <- gam(y~s(x,k=20))
plot(b);lines(x,f-mean(f),col=2);title("Ignoring correlation")
## Fit smooth, taking account of *known* correlation...[#适合平稳,考虑到*已知*相关...]
w <- solve(t(Cv)) # V^{-1} = w'w[V ^ {-1} = ww]
## Use `gam' to set up model for fitting...[#使用自由亚齐运动“成立的拟合模型...]
G <- gam(y~s(x,k=20),fit=FALSE)
## fit using magic, with weight *matrix*[#适合使用魔法与重量*矩阵,]
mgfit <- magic(G$y,G$X,G$sp,G$S,G$off,rank=G$rank,C=G$C,w=w)
## Modify previous gam object using new fit, for plotting... [#修改以前的GAM使用新的合适的对象,绘图...]
mg.stuff <- magic.post.proc(G$X,mgfit,w)
b$edf <- mg.stuff$edf;b$Vp <- mg.stuff$Vb
b$coefficients <- mgfit$b
plot(b);lines(x,f-mean(f),col=2);title("Known correlation")
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|