0
$\begingroup$

I have these values (negative and positive) and I want to determine the nonlinear relationship between variable and predictor using generalized additive models (GAMs).

df= data.frame(variable=c(-1.03391679,-1.324947736,-0.511549589,-0.890394361,-0.114783801,-0.607616663,-0.06972697,
                   0.10417567,0.346472235,0.566684541,0.552601689,0.146828173,0.352881477,0.105327722,
                   -0.199475689,0.381211487,1.793614103,0.714099845,-0.881529659,-0.946126372,-1.731426637,
                   -1.023895647,-1.155725351,-1.592679052,-0.788258216,-1.643160676,-1.073264013,-1.256619939,-0.840765857,
                   -0.502305706,-0.598869913,-0.70151056,-1.162473227,-0.817998155,-0.947264438,-0.909921175,
                   -1.015944272,-1.49645676,-0.894219391,-0.936551829,-0.977840436,-1.102238876,-1.236164349,
                   -1.30339163,-1.110259713,-1.592403782,-0.818693844,-1.517424033,-0.461633536,-0.887032296,-0.899936415,
                   -1.181668619,-0.760226407,-0.510525117,-0.276555603,-0.270391739,-0.763202415,-0.514927158,-0.207406064,
                   -0.514130386,-0.787170279,-0.998968675,-0.728808123,-0.590584485,-1.133567269,-1.020126191,
                   -1.035483352,-1.252052964,-1.701579112,-1.237738968,-0.133874299,-0.235070008,
                   -1.495950815,-0.974074072,-1.988234189,-1.168609357,-0.495524754,-0.401234574,0.007524237,0.332921197,
                   -0.007038695,-0.198511569,-0.576370464,-0.527011486,-0.493142973),
           date=c('2017-01-10','2017-01-24','2017-02-10','2017-02-21','2017-03-06','2017-03-20',
                       '2017-04-03',"2017-04-18","2017-05-05","2017-05-16","2017-06-17","2017-06-19",'2017-07-05',
                       "2017-07-21","2017-08-14","2017-08-29","2017-09-15","2017-10-18","2017-10-30",
                       "2017-11-14","2017-11-30","2017-12-13","2017-12-29","2018-01-23","2018-01-31",
                       "2018-02-16","2018-02-28","2018-03-14","2018-03-28","2018-04-13","2018-04-26",
                       "2018-05-16","2018-05-30","2018-06-15","2018-06-29","2018-07-16","2018-07-30",
                       "2018-08-14","2018-08-28","2018-09-17","2018-09-28","2018-10-12","2018-10-30",
                       "2018-11-15","2018-11-30","2018-12-13","2018-12-31","2019-01-18","2019-01-31",
                        "2019-02-15","2019-02-25","2019-03-14","2019-03-29","2019-04-15","2019-04-29",
                      "2019-05-17","2019-05-29","2019-06-18","2019-06-30","2019-07-19","2019-07-31",
                      "2019-08-15","2019-08-27","2019-09-16","2019-09-27","2019-10-15","2019-10-29",
                       "2019-11-14","2019-11-27","2019-12-13","2019-12-27","2020-01-16","2020-01-31","2020-02-13",
                       "2020-02-28","2020-03-12","2020-03-31","2020-04-16","2020-04-30","2020-05-14",
                       "2020-05-29","2020-06-15","2020-06-29","2020-07-15","2020-07-28"))

My variable has an almost "normal" distribution

shapiro.test(df$variable)
hist(df$variable)

But also, descdist tells me that the distribution is lognormal (but I have negative values)

descdist(cc_A$value, discrete=FALSE, boot=500)

My question is: What family can I use in my GAM if I have positive and negative values (I can't use Poison, gamma or other), and it's almost normal (and I don't want to transform).

I'm dealing with quasi-likelihood, but I don't know if it's okay, and I don't know how I can specify the link "" and the variance "".

The model are:

df$date<-as.POSIXct(df$date,"%Y-%m-%d",tz = "UTC")
df$date <- as.integer(as.Date(df$date, format = "%Y-%m-%d"))

mod1 <- mgcv::gam(variable ~s(date, bs="cr", k=10), data = df, method = "REML")

mod2 <- mgcv::gam(variable ~s(date, bs="cr", k=10), data = df, 
                   family=quasi(link = "identity", variance = "constant"), method = "REML")
summary(mod1)
summary(mod2)
```
$\endgroup$
7
  • 1
    $\begingroup$ Welcome to CV, Pablo. Why do you care about the distribution of your regression variables ($y$ or $x$)? GAMs will estimate relationships between both transformed and untransformed variables. Which (transformed or untransformed) do you substantively care about? $\endgroup$ – Alexis Apr 4 at 17:32
  • 1
    $\begingroup$ Hi @Alexis, thank you. I really thought that GAMs in mgcv need to specify the distribution family. I thought it was necessary for the penalty. Please, if I'm wrong, could you share a paper or book (S. Wood 2017 I already read it) about this. $\endgroup$ – Pablo Apr 4 at 18:32
  • 1
    $\begingroup$ We are interested in the conditional distribution of Y not the marginal distribution; what that means is we are not interested in the distribution of the raw response data. To choose a family, and you aren't familiar with which family might be used historically with such data, consider the properties of the response; yours is continuous and both positive and negative, so the options are somewhat limited in mgcv; start with gaussian() and then go form there, checking diagnostics etc. but the scat() family for a scaled t distribution is also possible $\endgroup$ – Gavin Simpson Apr 4 at 19:23
  • $\begingroup$ There's also the shash() family for the sinh-arcsinh distribution. Other distributions would be available in other packages such as the GAMLSS package. $\endgroup$ – Gavin Simpson Apr 4 at 19:27
  • $\begingroup$ Hi @GavinSimpson , thank you for your comment. When you say "then go from there, checking diagnostics" do you mean, run the models with different families (gaussian, scat, ...) and then compare them using, e.g., AIC, Deviance explained or R^2? And Yes, my values are negative and positive because I am standardizing (value - average) to compare the magnitude of the change before a disturbance (the first 15 dates are control, the rest are post-disturbance) $\endgroup$ – Pablo Apr 4 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.