找回密码
 注册
查看: 2031|回复: 0

R语言:smooth.construct()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-17 09:52:12 | 显示全部楼层 |阅读模式
smooth.construct(mgcv)
smooth.construct()所属R语言包:mgcv

                                        Constructor functions for smooth terms in a GAM
                                         在一个自由亚齐运动的顺利条款的构造函数

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

Smooth terms in a GAM formula are turned into smooth specification objects of  class xx.smooth.spec during processing of the formula. Each of these objects is converted to a smooth object using an appropriate smooth.construct function. New smooth classes  can be added by writing a new smooth.construct method function and a corresponding  Predict.matrix method function (see example code below).
在GAM公式顺利变成类xx.smooth.spec在处理公式的顺利规范对象。这些对象都被转换到一个平稳的对象使用一个合适的smooth.construct功能。可以添加新的平滑类写一个新的smooth.construct方法的功能和相应的Predict.matrix方法函数(见下面的示例代码)。

In practice, smooth.construct is usually called via smooth.construct2 and the wrapper function smoothCon, in order to handle by variables and centering constraints (see the smoothCon documentation if  you need to handle these things directly, for a user defined smooth class).
在实践中,smooth.construct通常被称为通过smooth.construct2和包装功能smoothCon,以处理by变量和定心的限制(见smoothCon文件你需要直接处理这些事情,一个用户定义的顺利类)。


用法----------Usage----------


smooth.construct(object,data,knots)
smooth.construct2(object,data,knots)



参数----------Arguments----------

参数:object
is a smooth specification object, generated by an s or te term in a GAM  formula. Objects generated by s terms have class xx.smooth.spec where xx is given by the  bs argument of s (this convention allows the user to add their own smoothers).  If object is not class tensor.smooth.spec it will have the following elements:     
是一个光滑的规范对象,产生一个s或te长期在GAM公式。所产生的对象s条款有类xx.smooth.spec其中xxbss(本公约允许用户添加自己的平滑)参数。 object如果是不是一流tensor.smooth.spec它将具备以下要素:

termThe names of the covariates for this smooth, in an array.  
termThe这个光滑的协变量的名称,在一个数组。

bs.dim Argument k of the s term generating the object. This is the dimension of the basis  used to represent the term (or, arguably, 1 greater than the basis dimension for cc terms).  bs.dim<0 indicates that the constructor should set this to the default value.  
bs.dim论证ks长期生成的对象。这是用来代表任期(或可以说,1比cc条款的基础上,尺寸更大)的基础维度。 bs.dim<0表明,构造应设置为默认值。

fixedTRUE if the term is to be unpenalized, otherwise FALSE.  
固定TRUE如果长期是要unpenalized,否则FALSE。

dimthe number covariates of which this smooth is a function.  
dimthe数量变项,其中平稳是一个函数。

p.orderthe order of the smoothness penalty or NA for autoselection of this. This is argument  m of the s term that generated object.  
p.orderthe为了平滑罚款或NA自动选择对本。这是参数ms长期生成的object的。

bythe name of any by variable to multiply this term as supplied as an argument to s.  "NA" if there is no such term.  
bythe任何by变量乘以这个词作为s的参数提供的名称。 "NA"如果有没有这样的术语。

labelA suitable label for use with this term.  
labelA适合标签使用这个词。

xtAn object containing information that may be needed for basis setup (used, e.g. by "tp" smooths to pass optional information on big dataset handling).  
xtAn对象,其中包含的信息可能需要基础设置的("tp"的,例如,平滑,通过对大数据集处理的可选信息)。

idAny identity associated with this term &mdash; used for linking bases and smoothing parameters. NULL by default, indicating no linkage.  
idAny的身份与这个词相关 - 用于连接基地和平滑参数。 NULL默认情况下,表示没有联动。

spSmoothing parameters for the term. Any negative are estimated, otherwise they are fixed at the supplied value. Unless NULL (default), over-rides sp argument to gam.     If object is of class tensor.smooth.spec then it was generated by a te term in the GAM formula,  and specifies a smooth of several variables with a basis generated as a tensor product of lower dimensional bases.  In this case the object will be different and will have the following elements:     
spSmoothing一词的参数。任何负面的估计,否则他们在所提供的值是固定的。除非NULL(默认),比乘坐sp参数gam。如果object是类tensor.smooth.spec的然后在GAM中公式的长期te生成,并指定几个变量的平稳与张量积产生的低维基地的基础。在这种情况下,对象会有所不同,并具备以下要素:

marginis a list of smooth specification objects of the type listed above, defining the bases which have  their tensor product formed in order to construct this term.  
marginis列表,上面列出的类型的顺利规范的对象,其中有他们的张产品形成以构建这个词的定义的基础。

termis the array of names of the covariates that are arguments of the smooth.  
TERMIS的顺利参数的协变量的名称的数组。

byis the name of any by variable, or "NA".  
byis任何by变量,或"NA"的名称。

fxis an array, the elements of which indicate whether (TRUE) any of the margins in the  tensor product should be unpenalized.  
fxis一个数组,其中表明是否(TRUE)张产品利润率应unpenalized元素。

labelA suitable label for use with this term.  
labelA适合标签使用这个词。

dimis the number of covariates of which this smooth is a function.  
dimis其中平稳是一个函数的协变量的数量。

mpTRUE if multiple penalties are to be used.  
MPTRUE如果要使用多个处罚。

npTRUE if 1-D marginal smooths are to be re-parameterized in terms of function values.  
NPTRUE如果一维边缘平滑函数值重新参数化。

idAny identity associated with this term &mdash; used for linking bases and smoothing parameters. NULL by default, indicating no linkage.  
idAny的身份与这个词相关 - 用于连接基地和平滑参数。 NULL默认情况下,表示没有联动。

spSmoothing parameters for the term. Any negative are estimated, otherwise they are fixed at the supplied value. Unless NULL (default), over-rides sp argument to gam.   
spSmoothing一词的参数。任何负面的估计,否则他们在所提供的值是固定的。除非NULL(默认),比乘坐sp参数gam。


参数:data
For smooth.construct a data frame or list containing the evaluation of the elements of object$term, with names given by object$term. The last entry will be the by variable, if object$by is not "NA". For smooth.construct2 data need only be an object within which object$term  can be evaluated, the variables can be in any order, and there can be irrelevant variables present as well.  
为smooth.construct一个数据框或列表包含评价object$term元素与object$term的名字。最后一个条目会的by变量,如果object$by不"NA"。 smooth.construct2data只需要内object$term可以评估,变量可以是任何顺序的对象,有可能是不相关的变量,目前以及。


参数:knots
an optional data frame or list containing the knots relating to object$term.  If it is NULL then the knot locations are generated automatically. The structure of knots should be as for data, depending on whether smooth.construct or smooth.construct2 is used.
一个可选的数据框或列表,其中包含有关object$term疙瘩。如果是的话NULL然后结位置自动生成。的knots的结构应该data的,取决于是否smooth.construct或smooth.construct2使用。


Details

详情----------Details----------

There are built in methods for objects with the following classes: tp.smooth.spec (thin plate regression splines: see tprs);  ts.smooth.spec (thin plate regression splines with shrinkage-to-zero); cr.smooth.spec (cubic regression splines: see cubic.regression.spline; cs.smooth.spec (cubic regression splines with shrinkage-to-zero); cc.smooth.spec (cyclic cubic regression splines); ps.smooth.spec (Eilers and Marx (1986) style P-splines: see p.spline); cp.smooth.spec (cyclic P-splines); ad.smooth.spec (adaptive smooths of 1 or 2 variables: see adaptive.smooth); re.smooth.spec (simple random effect terms); mrf.smooth.spec (Markov random field smoothers for smoothing over discrete districts); tensor.smooth.spec (tensor product smooths).
有建于对象的方法有以下类:tp.smooth.spec(薄板回归样条:见tprs)ts.smooth.spec(薄板收缩到零的回归样条); cr.smooth.spec(立方米回归样条:见cubic.regression.spline;cs.smooth.spec(立方米收缩到零的回归样条);cc.smooth.spec(循环三次回归样条);ps.smooth.spec (艾勒斯和马克思(1986)风格的P-样条:见p.spline)cp.smooth.spec(循环的P-样条);ad.smooth.spec(1或2个变量自适应平滑:看到<X )adaptive.smooth(简单的随机效应的条款);re.smooth.spec(离散区的平滑马尔可夫随机域平滑);mrf.smooth.spec(张量积平滑)。

There is an implicit assumption that the basis only depends on the knots and/or the set of unique  covariate combinations; i.e. that the basis is the same whether generated from the full set of covariates, or just the unique combinations of covariates.
有一个隐含的假设的基础上,只取决于节和/或一套独特的协组合,即基础是全套共变数,或只是独特的组合变项是否产生相同。

Plotting of smooths is handled by plot methods for smooth objects. A default mgcv.smooth method  is used if there is no more specific method available. Plot methods can  
光滑物体的图方法绘制的平滑处理。默认的mgcv.smooth方法,如果有没有更具体的方法可用。图方法


值----------Value----------

The input argument object, assigned a new class to indicate what type of smooth it is and with at least the  following items added:
object输入参数,指定一个新的类,以表明它是什么类型的顺利和至少增加下列项目:


参数:X
The model matrix from this term. This may have an "offset" attribute:  a vector of length nrow(X) containing any contribution of the smooth to the model offset term. by variables do not need to be dealt with here, but if they are then an item by.done must be added to the object.
从这个词的模型矩阵。这可能有一个"offset"属性:长度nrow(X)矢量包含任何贡献的顺利抵消长期模型。 by变量并不需要在这里处理,但如果他们是那么一个项目by.done必须添加到object。


参数:S
A list of positive semi-definite penalty matrices that apply to this term. The list will be empty  if the term is to be left un-penalized.
一个半正定罚款矩阵适用于本学期的列表。该列表会是空的,如果长期是要离开联合国惩罚。


参数:rank
An array giving the ranks of the penalties.
数组给予罚款的行列。


参数:null.space.dim
The dimension of the penalty null space (before centering).
罚款空空间的维数(前居中)。

The following items may be added:
可能会增加下列项目:


参数:C
The matrix defining any identifiability constraints on the term, for use when fitting. If this is NULL then smoothCon will add an identifiability constraint that each term should sum to zero over the covariate values. Set to a zero row matrix if no constraints are required. If a supplied C has an attribute "always.apply" then it is never ignored, even if any by variables of a smooth imply that no constraint is actually needed.  
矩阵定义任何可辨识的制约,对长期使用时,装修。如果这是NULL然后smoothCon将添加一个可辨识的约束,每学期应在协值总和为零。如果没有约束要求,设置了零行矩阵。如果提供的C属性"always.apply"那么它永远不会被忽略,即使任何by的顺利变量意味着没有约束的实际需要。


参数:Cp
An optional matrix supplying alternative identifiability constraints for use when predicting. By default the  fitting constrants are used. This option is useful when some sort of simple sparse constraint is required for fitting, but the  usual sum-to-zero constraint is required for prediction so that, e.g. the CIs for model components are as narrow as possible.  
一个可选的矩阵提供使用替代辨识限制时预测。默认情况下,装修constrants。此选项是很有用的一些简单的稀疏约束时需要装修,但平常的总和为零的约束预测必需的,这样,如模型组件独联体尽可能窄。


参数:no.rescale
if this is non-NULL then the penalty coefficient matrix of the smooth will not be  rescaled for enhaced numerical stability (rescaling is the default, because gamm requires it).  Turning off rescaling is useful if the values of the smoothing parameters should be interpretable in a model,  for example because they are inverse variance components.   
这是如果非NULL,则惩罚系数矩阵的顺利不会被重新调整为enhaced数值稳定性(缩放功能是默认的,因为gamm需要)。关闭缩放功能是非常有用的,如果平滑参数的值应该是在一个模型,例如解释,因为他们是逆差额组件。


参数:df
the degrees of freedom associated with this term (when unpenalized and unconstrained). If this is null then smoothCon will set it to the basis  dimension. smoothCon will reduce this by the number of constraints.
与这个词相关的自由度(当unpenalized和约束)。如果这是null,则smoothCon将其设置的基础层面。 smoothCon将减少人数的限制。


参数:te.ok
0 if this term should not be used as a tensor product marginal, 1 if  it can be used and plotted, and 2 is it can be used but not plotted. Set to 1 if NULL.
0如果这个词不应该被视为一个张量产品的边际,1如果它可以用来策划,和2是它可以使用,但不绘制。设置1如果NULL。


参数:plot.me
Set to FALSE if this smooth should not be plotted by plot.gam.  Set to TRUE if NULL.
设置为FALSE如果这个顺利不应绘制plot.gam。设置TRUE如果NULL。


参数:L
smooths may depend on fewer "underlying" smoothing parameters than there are elements of S. In this case L is the matrix mapping the vector of underlying log smoothing  parameters to the vector of logs of the smoothing parameters actually multiplying the S[[i]].  L=NULL signifies that there is one smoothing parameter per S[[i]].  
平滑可能依靠较少的“底层”平滑参数比有S元素。在这种情况下L其实乘以S[[i]]映射底层日志平滑参数平滑参数的日志向量的向量是矩阵。 L=NULL意味着每S[[i]]有一个平滑参数。

Usually the returned object will also include extra information required to define the basis, and used by  Predict.matrix methods to make predictions using the basis. See the Details section for links to the information included for the built in smooth classes.
通常返回的对象还包括额外的信息,需要定义的基础上,Predict.matrix方法使用的基础上作出的预测。 Details部分内置顺利类中包含的信息的链接。

tensor.smooth returned objects will additionally have each element of the margin list updated in the same way. tensor.smooths also have a list, XP, containing re-parameterization matrices for any 1-D marginal terms re-parameterized in terms of function values. This list will have NULL entries for marginal smooths that are not re-parameterized, and is only long enough to reach the last re-parameterized marginal in the list.  
tensor.smooth返回的对象将此外margin以同样的方式更新列表中的每个元素的。 tensor.smooths也有一个列表,XP,重新参数化矩阵包含任何重新参数化的函数值的1-D的边际条件。这份名单将有边际NULL条目平滑,不会重新参数化,只有足够长的时间,以达到在列表重新参数化的最后边际。


警告----------WARNING----------

User defined smooth objects should avoid having attributes names "qrc" or "nCons" as these are used internally to provide
用户定义的顺利对象应避免属性的名字"qrc"或"nCons"因为这些都是内部使用,以提供


作者(S)----------Author(s)----------


Simon N. Wood <a href="mailto:simon.wood@r-project.org">simon.wood@r-project.org</a>



参考文献----------References----------


generalized additive mixed models. Biometrics 62(4):1025-1036

University Press.
then the built in &quot;ps&quot; class is probably a better bet. It's based on
Statistical Science, 11(2):89-121


参见----------See Also----------

s,get.var, gamm, gam, Predict.matrix, smoothCon, PredictMat
s,get.var,gamm,gam,Predict.matrix,smoothCon,PredictMat


举例----------Examples----------


## Adding a penalized truncated power basis class and methods[#1受罚截断权力基础类和方法添加]
## as favoured by Ruppert, Wand and Carroll (2003) [#青睐Ruppert公司,魔杖和卡罗尔(2003)]
## Semiparametric regression CUP. (No advantage to actually[#半参数回归杯。 (没有实际的好处]
## using this, since mgcv can happliy handle non-identity [#使用此,自mgcv,可以happliy处理非同一性]
## penalties.)[#处罚。)]

smooth.construct.tr.smooth.spec<-function(object,data,knots)
## a truncated power spline constructor method function[#截断电源样条的构造方法功能]
## object$p.order = null space dimension[#对象p.order =空空间维度]
{ m <- object$p.order[1]
  if (is.na(m)) m &lt;- 2 ## default [#默认]
  if (m<1) stop("silly m supplied")
  if (object$bs.dim&lt;0) object$bs.dim &lt;- 10 ## default[#默认]
  nk&lt;-object$bs.dim-m-1 ## number of knots[#结]
  if (nk<=0) stop("k too small for m")
  x &lt;- data[[object$term]]  ## the data[#数据]
  x.shift &lt;- mean(x) # shift used to enhance stability[转移使用,以提高稳定性]
  k &lt;- knots[[object$term]] ## will be NULL if none supplied[#将NULL,如果没有提供]
  if (is.null(k)) # space knots through data[通过数据的空间结]
  { n<-length(x)
    k<-quantile(x[2n-1)],seq(0,1,length=nk+2))[2nk+1)]
  }
  if (length(k)!=nk) # right number of knots?[结的权数?]
  stop(paste("there should be ",nk," supplied knots"))
  x &lt;- x - x.shift # basis stabilizing shift[基础稳定的转变]
  k &lt;- k - x.shift # knots treated the same![节处理相同!]
  X<-matrix(0,length(x),object$bs.dim)
  for (i in 1m+1)) X[,i] <- x^(i-1)
  for (i in 1:nk) X[,i+m+1]<-(x-k[i])^m*as.numeric(x>k[i])
  object$X&lt;-X # the finished model matrix[完成的模型矩阵]
  if (!object$fixed) # create the penalty matrix[创建罚款矩阵]
  { object$S[[1]]<-diag(c(rep(0,m+1),rep(1,nk)))
  }
  object$rank&lt;-nk  # penalty rank[刑罚排名]
  object$null.space.dim &lt;- m+1  # dim. of unpenalized space[暗淡。 unpenalized空间]
  ## store "tr" specific stuff ...[#店“TR”具体的东西...]
  object$knots<-k;object$m<-m;object$x.shift <- x.shift

  object$df&lt;-ncol(object$X)     # maximum DoF (if unconstrained)[最大的自由度(如果不受约束)]

  class(object)&lt;-"tr.smooth"  # Give object a class[放弃反对一类]
  object
}

Predict.matrix.tr.smooth<-function(object,data)
## prediction method function for the `tr' smooth class[#TR顺利类预测方法的功能]
{ x <- data[[object$term]]
  x &lt;- x - object$x.shift # stabilizing shift[稳定的转变]
  m &lt;- object$m;     # spline order (3=cubic)[为了样条(3 =立方米)]
  k&lt;-object$knots    # knot locations[结的位置]
  nk&lt;-length(k)      # number of knots[结数]
  X<-matrix(0,length(x),object$bs.dim)
  for (i in 1m+1)) X[,i] <- x^(i-1)
  for (i in 1:nk) X[,i+m+1] <- (x-k[i])^m*as.numeric(x>k[i])
  X # return the prediction matrix[返回的预测矩阵]
}



# an example, using the new class....[例如,使用新的类....]
set.seed(100)
dat <- gamSim(1,n=400,scale=2)
b<-gam(y~s(x0,bs="tr",m=2)+s(x1,bs="ps",m=c(1,3))+
         s(x2,bs="tr",m=3)+s(x3,bs="tr",m=2),data=dat)
plot(b,pages=1)
b<-gamm(y~s(x0,bs="tr",m=2)+s(x1,bs="ps",m=c(1,3))+
         s(x2,bs="tr",m=3)+s(x3,bs="tr",m=2),data=dat)
plot(b$gam,pages=1)
# another example using tensor products of the new class[另一个例子,使用张新类产品]
dat <- gamSim(2,n=400,scale=.1)$data
b <- gam(y~te(x,z,bs=c("tr","tr"),m=c(2,2)),data=dat)
vis.gam(b)

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-1-23 07:06 , Processed in 0.023576 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表