s-news
[Top] [All Lists]

Re: [splus-users,14046] [S] gam(lo()) and predict.gam()

To: s-news@wubios.wustl.edu
Subject: Re: [splus-users,14046] [S] gam(lo()) and predict.gam()
From: Takezawa Kunio <takezawa@affrc.go.jp>
Date: Mon, 29 May 2000 20:13:43 +0900
In-reply-to: <200005290503.OAA00248@cabbage.math.keio.ac.jp>
References: <200005290503.OAA00248@cabbage.math.keio.ac.jp>
Sender: owner-s-news@wubios.wustl.edu
Hi! S-plus users.
E-mail: s-news@wubios.wustl.edu

   Let me modify the program I wrote in my previous
article. The two programs below work well.
I have heard that "<<-" and "rm())" are preferable
to "attach()" and "detach()". But I do not know
why.

-------------------- Program (C) --------------------
function()
{
        xx <- seq(from = 1, by = 1, to = 10)
        ex <- seq(from = 3, by = 0.3, length = 12)
        yy <- sin(xx) + 2
        data1 <<- data.frame(x = xx, y = yy)
        span1 <- 0.4
        formula.name <- paste("y ~ lo(x, span =", span1, ")")
        fit.gam <- gam(formula.name, data = data1, family = "poisson", x = T, 
model = T)
        data2 <- data.frame(x = ex)
        ey <- predict.gam(fit.gam, data2)
        rm(data1)
        ey
}
-------------------- End of Program (C) --------------------



-------------------- Program (D) --------------------
function()
{
        xx <- seq(from = 1, by = 1, to = 10)
        ex <- seq(from = 3, by = 0.3, length = 12)
        yy <- sin(xx) + 2
        data1 <- data.frame(x = xx, y = yy)
        attach(data1)
        span1 <- 0.4
        formula.name <- paste("y ~ lo(x, span =", span1, ")")
        fit.gam <- gam(formula.name, family = "poisson", x = T, model = T)
        data2 <- data.frame(x = ex)
        ey <- predict.gam(fit.gam, data2)
        detach("data1")
        ey
}
-------------------- End of Program (D) --------------------

   *****    Kunio Takezawa, Ph.D. (takezawa@affrc.go.jp)    *****
  *****            Research Information Section              *****
 **** Hokuriku National Agricultural Experiment Station, JAPAN ****
*****     <http://www.inada.affrc.go.jp/~takezawa/patent-e.html>    *****
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>