0

I’m experiencing an error when I try to use the smooth function in the gam function. My dataset has 7 rows, 9 predictors. This is my code.

y1=unlist(data1[11:17,2])

v1=unlist(data1[11:17,4])
v2=unlist(data1[11:17,5])
v3=unlist(data1[11:17,6])
v4=unlist(data1[11:17,7])
v5=unlist(data1[11:17,9])
v6=unlist(data1[11:17,10])
v7=unlist(data1[11:17,11])
v8=unlist(data1[11:17,12])
v9=unlist(data1[11:17,17])

xynew=data1

out1=gam(y1~s(v1,bs="cs",k=3)+v2+v3+v4+v5+v6+v7+v8+v9)
out2=gam(y1~v1+s(v2,bs="cs",k=3)+v3+v4+v5+v6+v7+v8+v9)
out3=gam(y1~v1+v2+s(v3,bs="cs",k=3)+v4+v5+v6+v7+v8+v9)
out4=gam(y1~v1+v2+v3+s(v4,bs="cs",k=3)+v5+v6+v7+v8+v9)
out5=gam(y1~v1+v2+v3+v4+s(v5,bs="cs",k=3)+v6+v7+v8+v9)
out6=gam(y1~v1+v2+v3+v4+v5+s(v6,bs="cs",k=3)+v7+v8+v9)
out7=gam(y1~v1+v2+v3+v4+v5+v6+s(v7,bs="cs",k=3)+v8+v9)
out8=gam(y1~v1+v2+v3+v4+v5+v6+v7+s(v8,bs="cs",k=3)+v9)
out9=gam(y1~v1+v2+v3+v4+v5+v6+v7+v8+s(v9,bs="cs",k=3))

And this is the error I’m getting back

Model has more coefficients than data

This is my first time coding in R for data analysis and prediction so it’ll mean a lot if any of you could help me out with this.

Thank you so much for your time and help.

  • 1
    Does this answer your question? [mgcv gam() error: model has more coefficients than data](https://stackoverflow.com/questions/36719799/mgcv-gam-error-model-has-more-coefficients-than-data) – user438383 Jun 14 '21 at 10:50
  • I read that too! However, I tried to change my values of k and I can’t seem to find a suitable value. – thediscreet Jun 14 '21 at 10:55
  • 2
    Your data apparently has 7 observations. You have 9 parameters + a smoother. This can't work. – Roland Jun 14 '21 at 10:57
  • Yeah I realised that after doing tons of research. But any idea what alternatives I can use for the modelling? – thediscreet Jun 14 '21 at 10:58
  • 2
    If you only have 7 observations, you shouldn't use a model with more than one independent variable. A smoother is out of the question. You need way more data to derive a sensible model. – Roland Jun 14 '21 at 12:17

0 Answers0