0
votes

I would like to apply a gam model on a dataset with specifying the types of functions to use.

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

s has to be the same function for both var1 and var2. I don't have a prior idea on s function family. If I resume, the model would find the constants (cst1 and cst2) plus the function 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.

1
var1 and var2 are one of the explicative variables and cst1, cst2 are multiplicative constants (numbers if you want). My dataset has 4 columns y, var1, var2 and var3 where y is the target. - mhaddad
Normally in a GAM the s() expands to a set of linear basis functions for your model, which serve the purpose of creating a flexible, smooth, but not technically nonlinear function of the predictor. If you want to combine these with multiplicative terms you may be getting into difficult waters. - Ben Bolker
I see... what should i use then? Thank you for your answer. - mhaddad
You may be able to use the linear basis functions around the difference of var1 and var2 i.e. s(var1-var2). On another matter, you don't need to specify the model parameterization (e.g. the exp() term) with GAM, that is the point of the non-linear basis functions. Does gam(y ~ s(var1) + s(var2), ...) not work? - vincentmajor

1 Answers

1
votes

This model could be fit with nls, the non-linear least squares package. 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. Basically you want to compute the coefficient vector A where the term is A * s(var1) + A * s(var2) = A * (s(var1) - s(var2)). You wouldn't want to just do s(var1 - var2); in general, f(x) - f(y) != f(x - y). To do this in R, you would

  1. Compute the spline basis matrices with ns() for var1 and var2, giving them the same knots. You need to specify both the knots and the Boundary.knots parameters so that the two splines will share the same basis.

  2. Subtract the two spline basis matrices (the output from the ns() function).

  3. Adapt the resulting subtracted spline basis matrix for the nls formula, as they do in the question I linked earlier.