6
$\begingroup$

I'm trying to predict high or low crime rate in municipalities (binary 1/0 response variable) using a range of socioeconomic variables. Im doing this with a panel dataset with 300 municipality over 17 years (2006-2016). To be more specific I train the model on data from 2006-2015 and then predict with data on features/predictors from 2016. The binary GAM I'm using for prediction has quite heavily autocorrelated residuals, how will this affect my predictions?

I have generally found very limited information on using panel/longitudinal data sets with binary response variables for prediction with Machine learning methods (Random Forest, Naive Bayes, K-NN) and would therefore also appreciate thoughts on this.

One thing that bugs me is how to make a model like random forest or GAM notice the id and time dimensions of a panel dataset.

$\endgroup$

1 Answer 1

7
$\begingroup$

The autocorrelation is going to affect any statistical inference you try to do with the model, such as testing is smooths are significant.

It is trivial to include random effects and spatio-temporal smooths in the GAM. You'll need to expand on what features you want to include in this model but, for example:

  • An isotopic spatial smoother (on coords x and y) plus region specific temporal trends all with same wiggliness (but not same shape) would include

    gam(y ~ s(x,y) + s(time, region, bs = 'fs'), data = foo, method = 'REML')
    
  • An isotropic spatial smoother plus region specific temporal trends with different wiggliness

    gam(y ~ region + s(x,y) + s(time, by = region), data = foo, method = 'REML')
    

and we can build up from there. For example, a Markov Random Field smooth can be used for the regions if they are areal data (administrative boundaries etc), and the random effect basis can be used if you want a random intercept per region or subject. (Note the above are using the syntax from the mgcv package.)

$\endgroup$
4
  • $\begingroup$ Hi im not sure I understand the definition of s(x,y). Also including s(time, region, bs = 'fs') in the model does not work. Doing this give the following error message: "Model has more coefficients than data". $\endgroup$
    – Niltzable
    Commented Jan 19, 2019 at 18:50
  • 2
    $\begingroup$ Without some indication of what you are doing exactly nor what your data look like, it's not going to be possible to help you. You asked some general questions and made some general statements, to which I offered general answers and and a specific refutation. You'll have to ask some specific questions (what is it about s(x,y) don't you grok? it is a spatial smoother but are you asking how it is formed?) or read Simon Wood's book or look at our course materials for more help. $\endgroup$ Commented Jan 21, 2019 at 21:32
  • $\begingroup$ The regions are municipalities. I have a panel data set with an id and time dimension. The id dimension is a character vector containing each of the 300 municipality names 17 times. The time dimension is a numeric vector containing the sequence (2000-2016) 300 times. l also have explanatory variables for each muncipality and year. I'm wondering if the spatial smoother procedure would be able to deal with autocorrelated residuals in my case. From what I understood in your comment it is usually formed with some type of spatial data (coordinates f.ex) which I dont have. Thx for your help so far. $\endgroup$
    – Niltzable
    Commented Jan 21, 2019 at 22:32
  • $\begingroup$ I assume you mean temporal autocorrelation then (?) as I don't see how you can control for spatial associations if you don't have spatial location covariates, beyond simple random effects or random smooths. $\endgroup$ Commented Jan 23, 2019 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.