简体   繁体   English

定义gam函数类型

[英]Defining gam function type

I would like to apply a gam model on a dataset with specifying the types of functions to use. 我想通过指定要使用的函数类型在数据集上应用gam模型。

It would be something like : y ~ cst1 * (s(var1)-s(var2)) * (1 - exp(var3*cst2)) 它将类似于: y ~ cst1 * (s(var1)-s(var2)) * (1 - exp(var3*cst2))

s has to be the same function for both var1 and var2 . 对于var1var2 s必须具有相同的功能。 I don't have a prior idea on s function family. 我对s函数族没有先见之明。 If I resume, the model would find the constants ( cst1 and cst2 ) plus the function s . 如果我继续,模型将找到常量( cst1cst2 )加上函数s

Is it possible? 可能吗? If not, is there any way (another type of models) i can use to do what i'm looking for? 如果没有,我有什么办法(另一种模型)可以用来做我想要的?

Thanks in advance for replies. 预先感谢您的答复。

This model could be fit with nls , the non-linear least squares package. 该模型可以与nls (非线性最小二乘包)拟合。 This will allow you to model the formula you want directly. 这将使您可以直接对所需的公式进行建模。 The splines will need to be done manually, though. 但是,花键将需要手动完成。 This question gets at what you would be trying to do. 这个问题涉及您将要做什么。

As far as getting the splines to be the same for var1 and var2 , you can do this by subtracting the basis matrices. 只要使var1var2的样条var1相同,就可以通过减去基本矩阵来实现。 Basically you want to compute the coefficient vector A where the term is A * s(var1) + A * s(var2) = A * (s(var1) - s(var2)) . 基本上,您想计算系数向量A ,其中项为A * s(var1) + A * s(var2) = A * (s(var1) - s(var2)) You wouldn't want to just do s(var1 - var2) ; 您不会只想做s(var1 - var2) in general, f(x) - f(y) != f(x - y) . 通常, f(x) - f(y) != f(x - y) To do this in R, you would 要在R中执行此操作,您将

  1. Compute the spline basis matrices with ns() for var1 and var2 , giving them the same knots . ns()计算var1var2的样条曲线基矩阵, 使它们的结数相同 You need to specify both the knots and the Boundary.knots parameters so that the two splines will share the same basis. 您需要同时指定knotsBoundary.knots参数,以便两个样条线共享相同的基础。

  2. Subtract the two spline basis matrices (the output from the ns() function). 减去两个样条曲线基矩阵( ns()函数的输出)。

  3. Adapt the resulting subtracted spline basis matrix for the nls formula, as they do in the question I linked earlier. 像在我之前链接的问题中所做的那样,将所得的减去的样条曲线基矩阵调整为nls公式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM