Skip to content
Prev 280167 / 398506 Next

shorter way of coding

Dear Sarah and R users, 

Thanks Sarah for the suggestion. The example you gave me works and I managed to get it to run by modifying the 'lm' to the gam command. 

y.list <- list(y1=runif(10), y2 <- runif(10), y3 <- runif(10))
x1 <- 1:10
x2 <- c(11, 15, 17, 2, 18, 6, 7, 8, 12, 10)
lapply(y.list, function(y)gam(y~s(x1,x2, k=100)))


I now face problem of getting the fitted results from the gam command. My original problem for only one y looked like this. Now how do I get to incorporate vis.gam(b) and fitted (b) into my new code? 

b<-gam(y~s(x1,x2,k=100),data=dat)
vis.gam(b)
fitted(b)

Many thanks once again.
Mintewab
________________________________________
Fr?n: Sarah Goslee [sarah.goslee at gmail.com]
Skickat: den 12 december 2011 17:36
Till: Mintewab Bezabih
Kopia: r-help at r-project.org
?mne: Re: [R] shorter way of coding

That's not a reproducible example. Paul suggested a list of formulas,
but I recommended creating a list of y variables.

In your attempt, you didn't include the y in the name of the dependent
variable; that's probably why it doesn't work.

Look at this:
$y1

Call:
lm(formula = y ~ x1)

Coefficients:
(Intercept)           x1
    0.56392     -0.02586


[[2]]

Call:
lm(formula = y ~ x1)

Coefficients:
(Intercept)           x1
    0.66375     -0.03519


[[3]]

Call:
lm(formula = y ~ x1)

Coefficients:
(Intercept)           x1
    0.29106      0.02845

Sarah

On Mon, Dec 12, 2011 at 11:21 AM, Mintewab Bezabih
<Mintewab.Bezabih at economics.gu.se> wrote:
--
Sarah Goslee
http://www.functionaldiversity.org