Questions tagged [gam]

GAM (Generalized Additive Model) is a statistical model used to combine Generalized Linear Models with Additive Models.

GAM (Generalized Additive Model) is a statistical model used to combine Generalized Linear models with Additive Models. It is found in both the CRAN packages gam and mgcv for the R language.

683 questions
0
votes
0 answers

Model predictions: how to manipulate dummy variables across time?

I'm trying to predict insect populations across a year. I've built my model (a GAM, using the package mgcv). I then used the predict() function after I built a dummy dataset to build this prediction off of . This is where I'm struggling. My question…
Heather
  • 21
  • 2
0
votes
1 answer

How to visualize natural cubic spline (ns) in the GAM

> # simulate some data... > dat <- gamSim(1,n=400,dist="normal",scale=2) > # fit model&plot > library(mgcv) > library(splines) > b0 <- gam(y~s(x1),data=dat) > plot(b0) Following the code above, I can get a plot like this: enter image description…
aisiqisdu
  • 1
  • 4
0
votes
0 answers

Fitting a GAM curve over a scatterplot?

I have a scatterplot of total seal abundance (Total) against observation period (Obsv_time): plot(Total ~ Obsv_time, data = R_Count) I have already created a gam exploring total abundance with windspeed and tide: gam.tot <- gam(Total ~…
Natalie Ward
  • 23
  • 1
  • 5
0
votes
1 answer

How to declare the exponential distribution in gam() in mgcv in R

I have a small dataset derived from an experiment and I want to fit a gam model prescribing the distribution of Y to be exponential with rate 0.5. My data is: x1 x2 y -1.000000 -1.000000 40 1.000000 -1.000000 5 -1.000000 …
user8270077
  • 4,621
  • 17
  • 75
  • 140
0
votes
1 answer

check_resid() function in itsadug package visualizing results of bam function in mgcv package returns error

I am going through the tutorial "Overview GAMM analysis of time series data" (http://www.sfs.uni-tuebingen.de/~jvanrij/Tutorial/GAMM.html) I fit a model with the following code: m1 <- bam(Y ~ Group + s(Time, by=Group) +…
user8270077
  • 4,621
  • 17
  • 75
  • 140
0
votes
1 answer

GAM in R with categorical AND continuous variables?

Wanting to see the effects of multiple variables on grey seal abundance (data collected from my MSc research) using a GAM or GAMM in R. My response variable is total count, and I have continuous variables of temperature, windspeed and categorical…
Natalie Ward
  • 23
  • 1
  • 5
0
votes
1 answer

Predict Command with GAM package in R

I am trying to use the predict command for gam functions in the "gam" package. I find that when I have two or more splines that I cannot predict onto a new sample, even if the new sample is the original data or a subset of the original data. The…
Charlie
  • 51
  • 3
0
votes
0 answers

First neural net - weights don't converge

i just wrote my first implementation of a neural network for the game tic-tac-toe. I have 9 input neurons (1,0,-1 for the state), and 1 output neuron (from -1 to 1 - that's the value of the state). I use a simple reinforcement algorithm: The…
beinando
  • 477
  • 4
  • 18
0
votes
1 answer

Spatially adaptive smoothing using mgcv package in R

I am using the gam function in the mgcv package to fit spatially adaptive smoothing for heterogeneous data. This is my R code for fitting. library(MASS) data(mcycle) fit <- gam(accel ~ s(times, k = 20, bs = 'ad'), data = mcycle, method = 'REML')…
NiroshaR
  • 53
  • 4
0
votes
1 answer

Error in seq(min(x), max(x), length = timesteps) : object 'a' not found within function

I'm trying to build a function that will plot my results. The second line in the function will give me the following error: Error in seq(min(x), max(x), length = timesteps) : object 'a' not found' Clearly a and b exist, because the gam is able to…
scriptgirl_3000
  • 161
  • 3
  • 16
0
votes
1 answer

gam in mgcv R with big number of covariates

I would like to know if there is another way to write the function: gam(VariableResponse ~ s(CovariateName1) + s(CovariateName2) + ... + s(CovariateName100), family = gaussian(link = identity), data = MyData) in mgcv package without typing 100…
Diep N.
  • 33
  • 7
0
votes
0 answers

Which type of spline should be used (package mgcv)?

Consider the code below: library(mgcv) x1 = runif(50) x2 = sample(1:10, 50, replace=T) y = rnorm(50) m = gam(y~s(x1)+s(x2)) Here are my questions: How can we extract (not determine) the type of spline and also the number of knots used for…
M. Er
  • 881
  • 1
  • 7
  • 13
0
votes
1 answer

Smooth terms are like a simple line in a generalized linear model (package mgcv)

I have fit a generalized additive model with a binary response using the code below: library(mgcv) attach(mydata) m = gam(y ~ dm + af + s(BMI) + s(sleepworkday), family=binomial(logit), data=mydata, method="REML") summary(m) Not that dm and af are…
M. Er
  • 881
  • 1
  • 7
  • 13
0
votes
0 answers

Retaining sample information after processing with a function in R

I won't pretend that this code is even remotely optimal, but here is the problem I have. I have a list of files with multiple columns read in with sapply(), such that if I call file.list[[1]] I get a summary of that data.frame, and…
user2472414
  • 131
  • 11
0
votes
1 answer

gamm models in R

I am trying to adapt my model to gamm (which I was using in lmer). My former formula was b <- lmer(metric1~a+b+c+d+e+f+g+h+i+(1|X) + (1|Y), data = dataset) I am trying to adapt this formula to modelling with gamm. But I could not figure out how…
borgs
  • 3
  • 5