Skip to content
Prev 263352 / 398502 Next

please help for mgcv package

On Tue, Jun 21, 2011 at 9:20 AM, Sarah Goslee <sarah.goslee at gmail.com> wrote:
Read the text carefully!!!
but this line is not what is in the book...I know it is not the
easiest to see, but those are ls not 1s.
At best this risks being confusing, at worst it could lead to errors.
If you use a for loop, it is good practice not to break the line (what
the good Dr. Wood does), or if you prefer to break the line, wrap it
in curly braces {}.  See ?for for the documentation.
Here is a copy (following my stylistic preferences, but should be
identical in function):

lag.sum <- function(a, l0, l1) {
  n <- length(a)
  b <- rep(0, n - l1)
  for (i in 0:(l1 - l0)) {
    b <- b + a[(i + 1):(n - l1 + i)]
  }
  b
}


Regarding what rep() does, see the documentation, ?rep  also, play
with simple examples to see its behavior:

rep(1, 10)
rep(1:3, 5)

If you are unfamiliar with R, you might have an easier go of it if you
read some of the myriad of online documentation/tutorials (or a book)
designed to introduce you to R.  GAMs is not really written to
introduce R, so it will be unnecessarily difficult to learn R from it.
 Here is one of the official manuals:

http://cran.r-project.org/doc/manuals/R-intro.html

Patrick Burns also has a number of tutorials for different levels of useRs:

http://www.burns-stat.com/pages/tutorials.html

HTH,

Josh