linear.functional.terms(mgcv)
linear.functional.terms()所属R语言包:mgcv
Linear functionals of a smooth in GAMs
GAMS平稳的线性泛函
译者:生物统计家园网 机器人LoveR
描述----------Description----------
gam allows the response variable to depend on linear functionals of smooth terms. Specifically dependancies of the form
gam允许响应变量依赖于平稳的线性泛函。具体的形式的依赖关系
are allowed, where the x_ij are covariate values and the L_ij are fixed weights. i.e. the response can depend on the weighted sum of the same smooth evaluated at different covariate values. This allows, for example, for the response to depend on the derivatives or integrals of a smooth (approximated by finite differencing or quadrature, respectively). It also allows dependence on predictor functions (sometimes called "signal regression").
是允许的,x_ij协的价值观和L_ij是固定的重量。即反应可以依靠的评估在不同的协价值观相同的顺利加权总和。这使得,例如,为响应依赖于衍生产品或积分顺利(有限差分或正交,分别近似)。它还可以依赖的预测功能(有时也被称为“信号回归”)。
The mechanism by which this is achieved is to supply matrices of covariate values to the model smooth terms specified by s or te terms in the model formula. Each column of the covariate matrix gives rise to a corresponding column of predictions from the smooth. Let the resulting matrix of evaluated smooth values be F (F will have the same dimension as the covariate matrices). In the absense of a by variable then these columns are simply summed and added to the linear predictor. i.e. the contribution of the term to the linear predictor is rowSums(F). If a by variable is present then it must be a matrix, L,say, of the same dimension as F (and the covariate matrices), and it contains the weights L_ij in the summation given above. So in this case the contribution to the linear predictor is rowSums(L*F).
这是实现机制是提供协值的矩阵s或te模型公式中的条款中指定的模式顺利条款。协矩阵的每一列产生相应列的顺利进行预测。让评估的顺利值矩阵是F(F将协矩阵有相同的维度)。然后在by变量由于缺少这些列只是总结,并添加到线性预测。长期的贡献,即线性预测是:rowSums(F)。如果by变量存在,那么它必须是一个矩阵,L的相同尺寸为F(和协矩阵),也就是说,它包含的重量L_ij在上述的总和。因此,在这种情况下,线性预测的贡献是rowSums(L*F)。
Note that if a L1 (i.e. rowSums(L)) is a constant vector, or there is no by variable then the smooth will automatically be centred in order to ensure identifiability. Otherwise it will not be. Note also that for centred smooths it can be worth replacing the constant term in the model with rowSums(L) in order to ensure that predictions are automatically on the right scale.
请注意,如果一个L1(即rowSums(L))是一个常数向量,或有没有by变量,然后顺利将自动为中心,以确保辨识。否则,它不会。还要注意,平滑中心,它可以取代模型中的常数项是值得rowSums(L)为了确保自动的预测是正确的规模。
When predicting from the model it is not necessary to provide matrix covariate and by variable values. For example to simply examine the underlying smooth function one would use vectors of covariate values and vector by variables, with the by variable and equivalent of L1, above, set to vectors of ones.
当从模型的预测是没有必要提供矩阵协变量和by变量值。例如,简单地检查底层的人会使用的协值的向量和向量by变量的光滑函数,by变量,相当于L1,上面设置的向量。
作者(S)----------Author(s)----------
Simon N. Wood <a href="mailto:simon.wood@r-project.org">simon.wood@r-project.org</a>
举例----------Examples----------
### matrix argument `linear operator' smoothing[#矩阵参数的线性算子平滑]
library(mgcv)
set.seed(0)
###############################[##############################]
## simple summation example...#[#的简单相加的例子...#]
###############################[##############################]
n<-400
sig<-2
x <- runif(n, 0, .9)
f2 <- function(x) 0.2*x^11*(10*(1-x))^6+10*(10*x)^3*(1-x)^10
x1 <- x + .1
f <- f2(x) + f2(x1) ## response is sum of f at two adjacent x values [#反应是在两个相邻的x值f的总和]
y <- f + rnorm(n)*sig
X <- matrix(c(x,x1),n,2) ## matrix covariate contains both x values[#矩阵协变量包含两个x值]
b <- gam(y~s(X))
plot(b) ## reconstruction of f[#重建的F]
plot(f,fitted(b))
######################################################################[################################################## ###################]
## multivariate integral example. Function `test1' will be integrated# [#多元积分的例子。 TEST1功能将被集成#]
## (by midpoint quadrature) over 100 equal area sub-squares covering # [#超过100个面积相等的子广场(中点正交)覆盖#]
## the unit square. Noise is added to the resulting simulated data. #[#单位的平方。噪声添加到由此产生的模拟数据。 #]
## `test1' is estimated from the resulting data using two alternative#[#TEST1估计从由此产生的数据使用两个替代#]
## smooths. #[#平滑。 #]
######################################################################[################################################## ###################]
test1 <- function(x,z,sx=0.3,sz=0.4)
{ (pi**sx*sz)*(1.2*exp(-(x-0.2)^2/sx^2-(z-0.3)^2/sz^2)+
0.8*exp(-(x-0.7)^2/sx^2-(z-0.8)^2/sz^2))
}
## create quadrature (integration) grid, in useful order[#创建一个正交(积分)网格,有用的顺序]
ig <- 5 ## integration grid within square[#广场内的一体化电网]
mx <- mz <- (1:ig-.5)/ig
ix <- rep(mx,ig);iz <- rep(mz,rep(ig,ig))
og <- 10 ## observarion grid[#observarion电网]
mx <- mz <- (1g-1)/og
ox <- rep(mx,og);ox <- rep(ox,rep(ig^2,og^2))
oz <- rep(mz,rep(og,og));oz <- rep(oz,rep(ig^2,og^2))
x <- ox + ix/og;z <- oz + iz/og ## full grid, subsquare by subsquare[#满格,由subsquare subsquare]
## create matrix covariates...[#创建矩阵协变量...]
X <- matrix(x,og^2,ig^2,byrow=TRUE)
Z <- matrix(z,og^2,ig^2,byrow=TRUE)
## create simulated test data...[#创建模拟测试数据...]
dA <- 1/(og*ig)^2 ## quadrature square area[#正交平方米面积]
F <- test1(X,Z) ## evaluate on grid[#评价网格]
f <- rowSums(F)*dA ## integrate by midpoint quadrature[#整合中点正交]
y <- f + rnorm(og^2)*5e-4 ## add noise[#增加噪声]
## ... so each y is a noisy observation of the integral of `test1'[#...所以每个y是一个TEST1积分嘈杂的观察“]
## over a 0.1 by 0.1 sub-square from the unit square[#以上0.1 0.1分方从单位正方形]
## Now fit model to simulated data...[#现在适合模型来模拟数据...]
L <- X*0 + dA
## ... let F be the matrix of the smooth evaluated at the x,z values[#...让F是评估顺利在X矩阵,z值]
## in matrices X and Z. rowSums(L*F) gives the model predicted[#在矩阵X和Z rowSums(长* F)的给模型预测]
## integrals of `test1' corresponding to the observed `y'[#test1的积分,相应的观测到的回答y]
L1 <- rowSums(L) ## smooths are centred --- need to add in L%*%1[#平滑中心---需要添加在L%* 1%]
## fit models to reconstruct `test1'....[#适合的模型来重建TEST1......]
b <- gam(y~s(X,Z,by=L)+L1-1) ## (L1 and const are confounded here)[#(L1和const混淆)]
b1 <- gam(y~te(X,Z,by=L)+L1-1) ## tensor product alternative[#张产品替代]
## plot results...[#图的结果......]
old.par<-par(mfrow=c(2,2))
x<-runif(n);z<-runif(n);
xs<-seq(0,1,length=30);zs<-seq(0,1,length=30)
pr<-data.frame(x=rep(xs,30),z=rep(zs,rep(30,30)))
truth<-matrix(test1(pr$x,pr$z),30,30)
contour(xs,zs,truth)
plot(b)
vis.gam(b,view=c("X","Z"),cond=list(L1=1,L=1),plot.type="contour")
vis.gam(b1,view=c("X","Z"),cond=list(L1=1,L=1),plot.type="contour")
####################################[###################################]
## A "signal" regression example...#[#一个“信号”回归例如...#]
####################################[###################################]
rf <- function(x=seq(0,1,length=100)) {
## generates random functions...[#生成随机函数...]
m <- ceiling(runif(1)*5) ## number of components[#组件]
f <- x*0;
mu <- runif(m,min(x),max(x));sig <- (runif(m)+.5)*(max(x)-min(x))/10
for (i in 1:m) f <- f+ dnorm(x,mu[i],sig[i])
f
}
x <- seq(0,1,length=100) ## evaluation points[#评估点]
## example functional predictors...[#例如功能预测...]
par(mfrow=c(3,3));for (i in 1:9) plot(x,rf(x),type="l",xlab="x")
## simulate 200 functions and store in rows of L...[#模拟200的功能和存储研究的行...]
L <- matrix(NA,200,100)
for (i in 1:200) L[i,] <- rf() ## simulate the functional predictors[#模拟功能预测]
f2 <- function(x) { ## the coefficient function[#系数函数]
(0.2*x^11*(10*(1-x))^6+10*(10*x)^3*(1-x)^10)/10
}
f <- f2(x) ## the true coefficient function[#真正系数功能]
y <- L%*%f + rnorm(200)*20 ## simulated response data[#模拟的响应数据]
## Now fit the model E(y) = L%*%f(x) where f is a smooth function.[#现在适合E型(Y)=%%* F(X),其中f是一个光滑函数。]
## The summation convention is used to evaluate smooth at each value[#求和约定是用来评价每个值的顺利]
## in matrix X to get matrix F, say. Then rowSum(L*F) gives E(y).[#矩阵X矩阵F说。然后rowSum(长*)给出了E(Y)。]
## create matrix of eval points for each function. Note that[#创建评估每个功能点的矩阵。请注意]
## `smoothCon' is smart and will recognize the duplication...[#smoothCon“是聪明,会承认的重复...]
X <- matrix(x,200,100,byrow=TRUE)
b <- gam(y~s(X,by=L,k=20))
par(mfrow=c(1,1))
plot(b,shade=TRUE);lines(x,f,col=2)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|