Dear users,
I am trying to show the equation (including coefficients from the model estimates) for a gam model but do not understand how to. Slide 7 from one of the authors presentations (gamtheory.pdf URL: http://people.bath.ac.uk/sw283/mgcv/) shows a general equation log{E(yi )} = α+ ßxi + f (zi ) . What I would like to do is put my model coefficients and present the equation used. I am an ecologist not a statistician  and have no access to statistical advice. How would I use values from the model below to complete the equation: log{E(yi )} = α+ ßxi + f (zi )? Many thanks, Darren ## from the help library(mgcv) set.seed(0) ## simulate some data... dat < gamSim(1,n=400,dist="normal",scale=2) b<gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=dat) summary(b) I have tried searching help forum with "gam equation" I was not able to find an answer from the 18 threads returned. Also tried looking at "?predict.gam" and simply "predict.gam" however my understanding of R is not sufficient to understand the details to be able to answer my question. I checked Simon Woods excellent presentations (http://www.maths.bath.ac.uk/~sw283/) however if the answer is there I am too stupid to see it. In truth the content assumes a level of basic understanding that I don't have. Unfortunately I do not have access to the book ( Wood S.N. (2006) Generalized Additive Models: An Introduction with R. Chapman and Hall/CRC Press.) or finances necessary to get it. Any help would be much appreciated, R version 2.10.1 (20091214) i386pcmingw32 locale: [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 [3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C [5] LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] mgcv_1.61 loaded via a namespace (and not attached): [1] grid_2.10.1 lattice_0.1726 Matrix_0.99937533 nlme_3.196 
On Thu, 20100304 at 14:49 0800, doon75 wrote:
> Dear users, > I am trying to show the equation (including coefficients from the model > estimates) for a gam model but do not understand how to. > Slide 7 from one of the authors presentations (gamtheory.pdf URL: > http://people.bath.ac.uk/sw283/mgcv/) shows a general equation > log{E(yi )} = α+ ßxi + f (zi ) . That would be the model for the Gamma GAM. > What I would like to do is put my model coefficients and present the > equation used. I am an ecologist not a statistician  and have no access to > statistical advice. > How would I use values from the model below to complete the equation: > log{E(yi )} = α+ ßxi + f (zi )? > Many thanks, > Darren > > ## from the help > library(mgcv) > set.seed(0) ## simulate some data... > dat < gamSim(1,n=400,dist="normal",scale=2) > b<gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=dat) > summary(b) coef(b) will give you the coefficients for the smooth terms + the intercept for that model. ?gamObject describes thus a little. The coefficients for the smooth/spline terms here are of length 9 each, and each set of 9 coefficients pertains to an f(), so the model in the R code you gave would be something like E(y_i) ~ alpha + f_1(x0_i) + f_2(x1_i) + f_3(x2_i) +f_4(x3_i) or E(y_i) = alpha + f_1(x0_i) + f_2(x1_i) + f_3(x2_i) +f_4(x3_i) + e, where e ~ N(0, sigma) The first number returned by coef(b) is the intercept term, the alpha above. The next 9 numbers are the coefficients for the spline (f_1) fitted to the variable x0, and so on. These coefficients relate to the set of basis functions used to represent the spline for each covariate (x0, x1 etc). Depending on why you want to write out the equation, you may not need the detail provide at the level of the coefficients. Are the equations above sufficient for your needs? I'm an ecologist too and rarely do I need to think about the models I am working with at the level of the coefficients for the basis functions, but your needs may be different. If so, perhaps you could provide more details on why you want the equation for the model? HTH G > > I have tried searching help forum with "gam equation" I was not able to > find an answer from the 18 threads returned. > Also tried looking at "?predict.gam" and simply "predict.gam" however my > understanding of R is not sufficient to understand the details to be able to > answer my question. > I checked Simon Woods excellent presentations > (http://www.maths.bath.ac.uk/~sw283/) however if the answer is there I am > too stupid to see it. In truth the content assumes a level of basic > understanding that I don't have. Unfortunately I do not have access to the > book ( Wood S.N. (2006) Generalized Additive Models: An Introduction with R. > Chapman and Hall/CRC Press.) or finances necessary to get it. > Any help would be much appreciated, > > R version 2.10.1 (20091214) > i386pcmingw32 > > locale: > [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United > Kingdom.1252 > [3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C > [5] LC_TIME=English_United Kingdom.1252 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > other attached packages: > [1] mgcv_1.61 > > loaded via a namespace (and not attached): > [1] grid_2.10.1 lattice_0.1726 Matrix_0.99937533 nlme_3.196 %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/rhelp PLEASE do read the posting guide http://www.Rproject.org/postingguide.html and provide commented, minimal, selfcontained, reproducible code. 
I have spent a few days trying to figure this from the reply out but am still stuck!
I need the equation to reply to a request from a referee that was to: "show the specific estimating equation associated with the fitted line". the model I am running is (I hope the data frame is not necessary as I think I am just not getting some basic concept, but it can be provided off list): gam1<gam(LR~s(Property_lg),data=property) ## use default family gaussian(link = "identity") coef(gam1) returns: (Intercept) s(Property_lg).1 s(Property_lg).2 s(Property_lg).3 s(Property_lg).4 s(Property_lg).5 44.1777350 9.4673457 1.5743877 0.5658906 2.2219434 0.4118942 s(Property_lg).6 s(Property_lg).7 s(Property_lg).8 s(Property_lg).9 2.4477335 0.6590291 14.6142365 3.4184510 so is the "estimating equation": E(y_i) ~ 44.1777 + f_1(9.467) + f_2(1.574) + f_3(0.565) +f_4(2.221) + f_5(0.411) + f_6(2.447) + f_7(0.659) +f_8(14.614)+f_9(3.418) From the “predict” function I know the fitted value at x = 0 (intercept) is 25.5256255 and at x = 1 is 1.3417508. How do I calculate these values from the “estimating equation” above? For x=1, I am doing the calculation below which is obviously incorrect, but how do I calculate the predicted values by hand, I must be missing something incredibly obvious? 44.1777 + (1*9.467) + (1*1.574) + (1*0.565) + (1*2.221) + (1*0.411) + (1*2.447) + (1*1*0.659) + (1*4.614)+ (1*3.418) Many thanks for any further guidance, Darren <quote author="Gavin Simpson"> coef(b) will give you the coefficients for the smooth terms + the intercept for that model. ?gamObject describes thus a little. The coefficients for the smooth/spline terms here are of length 9 each, and each set of 9 coefficients pertains to an f(), so the model in the R code you gave would be something like E(y_i) ~ alpha + f_1(x0_i) + f_2(x1_i) + f_3(x2_i) +f_4(x3_i) or E(y_i) = alpha + f_1(x0_i) + f_2(x1_i) + f_3(x2_i) +f_4(x3_i) + e, where e ~ N(0, sigma) If so, perhaps you could provide more details on why you want the equation for the model? 
Darren,
Sorry for the slow reply. This is probably much to late to be of use to you now. I think that the referee is being unreasonable here. There are many perfectly respectable ways of estimating GAMs for which no explicit expression for the estimated smooth terms is available (See Hastie and Tibshirani's GAM book). mgcv actually does use smoothers that can be represented explicitly, but it is completely unilluminating to do so. I've attached a paper describing exactly how the smooths you have used are represented. You could provide the referee with expression (7), and the description of how \delta_i and \alpha_i are obtained from the coefficients actually estimated, but it's not going to help the paper's readers much. best, Simon On Thursday 11 March 2010 16:22, Darren Norris wrote: > I have spent a few days trying to figure this from the reply out but am > still stuck! > I need the equation to reply to a request from a referee that was to: "show > the specific estimating equation associated with the fitted line". > the model I am running is (I hope the data frame is not necessary as I > think I am just not getting some basic concept, but it can be provided off > list): gam1<gam(LR~s(Property_lg),data=property) ## use default family > gaussian(link = "identity") > > coef(gam1) returns: > (Intercept) s(Property_lg).1 s(Property_lg).2 s(Property_lg).3 > s(Property_lg).4 s(Property_lg).5 > 44.1777350 9.4673457 1.5743877 0.5658906 > 2.2219434 0.4118942 > s(Property_lg).6 s(Property_lg).7 s(Property_lg).8 s(Property_lg).9 > 2.4477335 0.6590291 14.6142365 3.4184510 > > so is the "estimating equation": > E(y_i) ~ 44.1777 + f_1(9.467) + f_2(1.574) + f_3(0.565) +f_4(2.221) + > f_5(0.411) + f_6(2.447) + f_7(0.659) +f_8(14.614)+f_9(3.418) > > >From the “predict” function I know the fitted value at x = 0 (intercept) > > is > > 25.5256255 and at x = 1 is 1.3417508. How do I calculate these values > from the “estimating equation” above? > For x=1, I am doing the calculation below which is obviously incorrect, but > how do I calculate the predicted values by hand, I must be missing > something incredibly obvious? > 44.1777 + (1*9.467) + (1*1.574) + (1*0.565) + (1*2.221) + (1*0.411) + > (1*2.447) + (1*1*0.659) + (1*4.614)+ (1*3.418) > > Many thanks for any further guidance, > Darren > > > > coef(b) > > will give you the coefficients for the smooth terms + the intercept for > that model. ?gamObject describes thus a little. > > The coefficients for the smooth/spline terms here are of length 9 each, > and each set of 9 coefficients pertains to an f(), so the model in the R > code you gave would be something like > > E(y_i) ~ alpha + f_1(x0_i) + f_2(x1_i) + f_3(x2_i) +f_4(x3_i) > > or > > E(y_i) = alpha + f_1(x0_i) + f_2(x1_i) + f_3(x2_i) +f_4(x3_i) + e, where > e ~ N(0, sigma) > > > If so, perhaps you could provide more details on why you want the > equation for the model? > Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK > +44 1225 386603 www.maths.bath.ac.uk/~sw283 ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/rhelp PLEASE do read the posting guide http://www.Rproject.org/postingguide.html and provide commented, minimal, selfcontained, reproducible code. tprs.pdf (1M) Download Attachment 
This post has NOT been accepted by the mailing list yet.
In my case, I need an explicit equation with the smoothing splines expanded so that I can insert this equation in a piece of C# code which will then predict for new cases. How can I expand the smooth functions in terms of the coefficients?

Powered by Nabble  Edit this page 