6
$\begingroup$

I am currently constructing a GAM model to describe house prices. The dataset is a collection of roughly 200K house sales in a particular geographic region. Based on previous suggestions in this forum, the mean house price $p_{i}$ is modelled as:

$$ \ln (p_{i}) = \sum_{j}s_{j}(x_{i,j}) \ \ , \ \ P_{i} \sim Tweedie(p_{i}) $$

, where $s_{j}$ denotes the jth smooth for my set of covariates, which are geograpgic location, house size, lot size etc. etc. Due to the strict positivity of prices, I have found that the combination of a log-link and a Tweedie-distribution provides best results measured by out-of-sample error (however, a Gamma-distribution with log-link also does quite well - see my previous post Simulating from fitted t-distribution mgcv for details on this).

In search for the best model I have tried a range of different covariates and arrived at a model, that I believe to be the optimal in terms of balance between predictive capability and parsimony. I am however concerned about the results I get when applying the model checking routine offered by mgcv (or appraise() in the gratia library) as shown below:

enter image description here

Evidently the results based on the QQ-plot suggest, that my model are not able to capture the fat tails in my distribution. Also the residual vs linear predictor plot is not a flat band as one would hope but has some systematic linear component in the first part of the negative residuals - I suspect that this has something to do with the fact that the model can only output positive values.

As I do have limited experience with model checking of GAMs, I therefore want to ask the following question to those that have more experience in the field:

Do the above model diagnostics indicate a serious problem in my model, or are they within the tolerance of what one generally would accept? And if so, what are the general rules of thumb that people use when assesing model quality based on QQ-plots etc.

Addition to original question based on answer from Gavin Simpson:

As Gavin correctly points out the above question is not sufficiently detailed for one to be able to provide concrete suggestions. While I am not allowed to share the data I am working with I below add details on the exact model used to obtain diagnostics described in the original question.

The model I used is based on fitting a data set of 222299 house sales with the following information:

  1. Response variable: House price per square meter, P

  2. Covariates:

Coordinates, (x,y)
Sales date, t (converted to an integer)
Building size, A
Lot size, L
Construction year, Y
Distance to coast, D1
Distance to lake, D2
Distance to railway station, D3
Distance to highway, D4
Roof type (categorial variable), R
Wall type (categorial variable), W
Heating source (categorical variable), H

The distance variables are special. These are either in the interval [0, 1000] or 10000 (a large number to indicate they are far away from the entity in question).

The model I specify in mgcv has the following form:

model <- mgcv::bam(P ~ s(x, y, k = 4000) +
                       s(t, k = 10, pc = 0) +
                       s(Y, k = 8, pc = 1970) +
                       s(A, k = 5, pc = 140) +                                   
                       s(L, k = 5, pc = 800) +
                       s(D1, k = 5, pc = 10000) +                   
                       s(D2, k = 5, pc = 10000) +
                       s(D3, k = 5, pc = 10000) +
                       s(D4, k = 5, pc = 10000) +
                       R +
                       W +
                       H,
                       data = data,
                       family = tw(link=log),
                       method = "fREML")
$\endgroup$
3
  • $\begingroup$ I'm not sure if this would help in your case, but you could perhaps try fitting this as a location-scale GAMLSS model, where rather than just modeling the mean of the response as smooth, you could perhaps allow the variance to flexibly vary instead. The original GAMLSS book by Stasinopoulos shows examples of these kinds of models. Again, not confident it will work in your model, but given you mentioned the variance issue, this could be a potential fix. $\endgroup$ Commented Jun 23 at 15:27
  • $\begingroup$ Have you looked at your outliers? Maybe you can identify why they are so over/under estimated and add additional variables to your model. Also your response cuts off at 100,000 which might be causing problems and is definitely not what the model would predict. $\endgroup$ Commented Jun 23 at 19:14
  • $\begingroup$ Do you have a clue what is the cost of a wrong regression? Is it more important to get the cheap or expensive house prices right? You might want to consider Cost-sensitive regression $\endgroup$
    – Ggjj11
    Commented Jun 24 at 7:17

1 Answer 1

3
+50
$\begingroup$

The problem with large data sets is that heterogeneities often become visible. With a location-only model, you are fitting a model that also includes constant "effects" for $p$ and $\varphi$, the power and scale parameters of the Tweedie distribution. As a result, if you are going to fit a location-only model, the model can only fit the data with a constant mean-variance relationship. This is often inflexible to sufficiently model the heterogeneities in large data sets.

There are clear problems with this model; the data are more dispersed than expected under a Tweedie with $\hat{p} = 1.242$ and $\hat{\varphi}$ constant.

This could be modelled with extra terms in the location linear predictor; as you don't actually specify what the model that you fitted it is (why don't you ever post this useful information?), it's impossible to give concrete advice. If the data are spatially distributed, adding a spatial smooth might help. If the data are clustered in some way to neighbourhoods, then a random effect or Markov random field smooth could be used to account for effects related to desirable vs less-desirable neighbourhoods, the latter accounting for the spatial relationship too.

Beyond that, if the diagnostics remain bad, you'll need to move to a more complex model and start modelling the $p$ and $\varphi$ parameters with linear predictors. For this you'll need to fit with gam() and use the twlss() family (or you could also try the gammals() family if you prefer to fit a Gamma location-scale model).

As there is less information in the data about the power and scale parameters (and thence variance and other higher moments) than there is for the mean (location), you should start the model off with simple effects in the linear predictors for $p$ and $\varphi$ (if fitting with twlss()) or $\varphi$ (if fitting with gammals()). For example, include any random effects or Markov random field smooths to capture potentially gross differences due to (spatial)clustering in the data - i.e. the neighbourhood effects.

The mgcViz package has additional diagnostic plots that can be used to help diagnose the need for a location scale shape (aka "distributional model").

$\endgroup$
6
  • $\begingroup$ Hi Gavin, thank you once again for a very elaborate answer. I am not allowed to share the data I work with, but I have edited the original question showing the model I used to obtain the above model diagnostics. As you can see I already try to model the spatial component of the data using a bivariate splane s(x,y) with quite a lot of basis functions (therefore the choice of bam() instead of gam()), so I do not think this is what causes the bad model diagnostics. I have also tried to get the location-scale modelling working, but so far without succes (details of this in the original post). $\endgroup$ Commented Jun 25 at 11:11
  • 1
    $\begingroup$ Like I said in my answer, fit the model with linear predictors for the other distributional parameters. Read ?twlss or ?gammals for details an the linked man pages. I'm a little unconvinced by the distances; faking a value is going to force the spline to take some shape which might be undesirable. Why can't you just include the actual distances and let the model decide how distances > 1000 affect the response? Unless you have a very wiggly spatial process, 4000 seems excessive. You can't fit LSS models (yet) with bam(), so you need to go to gam(). There's not much more I can add. $\endgroup$ Commented Jun 25 at 11:11
  • $\begingroup$ In reality I don't measure the distances. They are provided to me and come as either a number between [0,1000] or as 10000. The 10000 simply means that the distance was beyond 1000 and therefore not measured. It also means that the form of the spline above 1000 does not matter, as these values are never used for prediction. But if you have a suggestion on how to do it better I am curious. $\endgroup$ Commented Jun 25 at 11:18
  • 1
    $\begingroup$ One way to handle that could be to add a term to the model for long distance (a two-level factor), and also create a variable short <- as.numeric(distance < 1001) and use this in the smooth of distance s(distance, by = short). Because short is a numeric, the smooth of distance will only apply to those observations where you actually have the distance measured. You probably also want to fiddle with the knots to place most of them between 0 and 1000 (so use a spline that is knot-based, i.e. not the default basis). $\endgroup$ Commented Jun 25 at 14:14
  • $\begingroup$ Hello Gavin. I have been thinking about your suspicion about the choice of 4000 basis functions for the spatial process being excessive unless it were extremely wiggly. My reason for this choice is that I see the model test error keeps going down even for >3000 basis functions. $\endgroup$ Commented Jun 28 at 9:19

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.