5

I use R version 2.15.1 (2012-06-22) and mgcv version 1.7-22

I load the following set of packages in R:


library(sqldf)
library(timeDate)
library(forecast)
library(xts)
library(tseries)
library(MASS)
library(mgcv)

It happens that I can not run a simple model (I omit the code). Even the sample code taken from the help pages:


dat = gamSim(1,n=400,dist="normal",scale=2)
b = gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=dat)

gives an error:


Error in qr.qty(qrc, sm$S[[l]]) : 
  NA/NaN/Inf in foreign function call (arg 5)
In addition: Warning message:
In smoothCon(split$smooth.spec[[i]], data, knots, absorb.cons, scale.penalty = scale.penalty,  :
  number of items to replace is not a multiple of replacement length

Note that everything works fine, if I just load the package mgcv and then use the sample code right away. It also works if I just load all the packages and run the sample code. It just does not work if I

  1. load all packages
  2. do some file reading, sqldf statements, ts operations and some models from package forecast.
  3. if I then apply GAM, it does not work anymore.

Apparently the variable definitions in the general environment mess up the functioning of the package.

Are there any known issues? Are there general rules that I have to obey if I load various packages? Can I write code that "disturbed" the package mgcv?

Richi W
  • 3,534
  • 4
  • 20
  • 39
  • Your step (2) is a little vague. You're probably going to need to narrow it down to something more specific that triggers the problem. – joran Feb 15 '13 at 17:45
  • 1
    I used to get similar error message when I inadvertently load the other gam package with mgcv. Make sure they are not both loaded at the same time – Meso Feb 15 '13 at 18:36
  • @Meso: which other GAM package do you mean? – Richi W Feb 17 '13 at 22:00
  • @joran I use quite a few commands. Right now I tried not to load tseries and MASS and so far it works ... it just scares me that it could break down if I load the wrong package or call the wrong function. – Richi W Feb 17 '13 at 22:01

2 Answers2

2

@ Richard there are 2 GAM related packages: gam and mgcv. Loading both libraries at the same time usually causes a conflict.

Meso
  • 1,375
  • 5
  • 17
  • 36
  • as a starting point, look under "Reverse Depends" here: http://cran.r-project.org/web/packages/gam/index.html to see the packages that will load `gam` automatically: ares, bandit, CausalGAM, ddepn, GAMens, LSC, MapGAM, mtsdi, ProDenICA, pscl, RPPanalyzer, xpose4, xpose4specific – Ben Bolker Feb 18 '13 at 21:15
  • @Ben Bolker I admit that I was wrong. Never heard of any in the list. I work in environmental epidemiology and GAM and mgcv are the ones that are mostly used. thanks for that – Meso Feb 18 '13 at 22:17
  • that doesn't mean you're wrong -- there might be more than one link in the chain, i.e. one of these packages might be loaded by one of the other ones the OP loaded directly ... – Ben Bolker Feb 19 '13 at 01:20
  • Hi, I have kicked out packages that I will certainly not need. The list reduces to library(mgcv) library(sqldf) library(timeDate) library(forecast) library(xts) I will go through these. It is just a pity because I have been using R for quite a while and I never had compatibility problems. – Richi W Feb 19 '13 at 16:16
0

Loading mgcv as the first package solved my problem ... strange but true.

Richi W
  • 3,534
  • 4
  • 20
  • 39
  • Is this a general rule, that one has to load packages first whose functions should rank higher in the look-up for function names? – Richi W Feb 20 '13 at 08:48