Skip to content
Prev 280072 / 398506 Next

shorter way of coding

Dear Paul and Sarah

Thanks for the suggestion. I have provided my data here in to make the results reproducable. I am actually trying to do interpoliation of climate data where x1 and x2 are my latitude and longitude and sum64-sum 368 are my rainfall observations which I need to regress against x1 and x2. In the previous I was trying to get my story clear so I did not go into details. 

Now when I run your suggestion below, I get the following error message. Is there anything in your instruction that I did not get right?
many thanks
mintewab

listOfForumlas = paste(1:300, "~s(x1,x2, k=100)")
listofResults = lapply(listOfForumlas, function(f) {
    b<-gam(as.formula(f),data=dat)
    vis.gam(b)
    fitted(b)
  })

Error in model.frame.default(formula = 1 ~ 1 + x1+ x2, data = dat,  : 
  variable lengths differ (found for 'x1')

________________________________________
Fr?n: Paul Hiemstra [paul.hiemstra at knmi.nl]
Skickat: den 12 december 2011 14:42
Till: Mintewab Bezabih
Kopia: r-help at r-project.org
?mne: Re: [R] shorter way of coding
On 12/12/2011 01:16 PM, Mintewab Bezabih wrote:
Hi Mintewab,

Something along these lines should work:

listOfForumlas = paste(1:300, "~s(x1, x2, k=100)")
listofResults = lapply(listOfForumlas, function(f) {
    b<-gam(as.formula(f),data=dat)
    vis.gam(b)
    fitted(b)
  })

But as Sarah already commented, without a reproducible piece of example
code we cannot present any working solutions.

cheers,
Paul

--
Paul Hiemstra, Ph.D.
Global Climate Division
Royal Netherlands Meteorological Institute (KNMI)
Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
P.O. Box 201 | 3730 AE | De Bilt
tel: +31 30 2206 494

http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770