title: How to change the y-axis for a multivariate GAM model from smoothed to actual values?
body: <p>I am using multivariate GAM models to learn more about fog trends in multiple regions. Fog is determined by visibility going below a certain threshold (&lt; 400 meters). Our GAM model is used to determine the response of visibility to a range of meteorological variables.</p>
  <p>However, my challenge right now is that I'd really like the  y-axis to be the actual visibility observations rather than the centered smoothed. It <em>is</em> interesting to see how visibility is impacted by the covariates relative to the mean visibility in that location, but it's difficult to compare this for multiple locations where the mean visibility is different (and thus the 0 point in which visibility is enhanced or diminished has little comparable meaning).</p>
  <p>In order to compare the results of multiple locations, I'm trying to make the y-axis actual visibility observations, and then I'll put a line at the visibility threshold we're interested in looking at (400 m)
  to evaluate what the predictor variables values are like below that threshold (eg what temperatures are associated with visibility below 400 m).</p>
  <p>I'm still a beginner when it comes to GAMs and R in general, but I've figured out a few helpful pieces so far.</p>
  <p>Helpful things so far:</p>
  <p>Attempt 1. how to extract gam fit for each variable in model
  <a href="https://stackoverflow.com/questions/15843654/extracting-data-used-to-make-a-smooth-plot-in-mgcv/15843897#15843897">Extracting data used to make a smooth plot in mgcv</a></p>
  <p>Attempt 2. how to use predict function to reconstruct a univariable model
  <a href="http://zevross.com/blog/2014/09/15/recreate-the-gam-partial-regression-smooth-plots-from-r-package-mgcv-with-a-little-style/" rel="nofollow noreferrer">http://zevross.com/blog/2014/09/15/recreate-the-gam-partial-regression-smooth-plots-from-r-package-mgcv-with-a-little-style/</a></p>
  <p>Attempt 3. how to get some semblance of a y-axis that looks like visibility observations using &quot;fitted&quot; -- though I don't think this is
  the correct approach since I'm not taking the intercept into account
  <a href="http://gsp.humboldt.edu/OLM/R/05_03_GAM.html" rel="nofollow noreferrer">http://gsp.humboldt.edu/OLM/R/05_03_GAM.html</a></p>
  <h1>simulated data</h1>
  <pre><code>install.packages(&quot;mgcv&quot;) #for gam package
  require(mgcv)
  install.packages(&quot;pspline&quot;)
  require(pspline)
  
  
  #simulated GAM data for example
  dataSet &lt;- gamSim(eg=1,n=400,dist=&quot;normal&quot;,scale=2)
  visibility &lt;- dataSet[[1]]
  temperature &lt;- dataSet[[2]]
  dewpoint &lt;- dataSet[[3]]
  windspeed &lt;- dataSet[[4]]
  
  
  #Univariable GAM model
  gamobj &lt;- gam(visibility ~  s(dewpoint))
  plot(gamobj, scale=0, page=1, shade = TRUE, all.terms=TRUE, cex.axis=1.5, cex.lab=1.5, main=&quot;Univariable Model: Dew Point&quot;)
  summary(gamobj)
  AIC(gamobj)
  abline(h=0)
  </code></pre>
  <p>Univariable Model of Dew Point
  <a href="https://imgur.com/1uzP34F" rel="nofollow noreferrer">https://imgur.com/1uzP34F</a></p>
  <h1>ATTEMPT 2 -- predict function with univariable model, but didn't change y-axis</h1>
  <pre><code>#dummy var that spans length of original covariate
  maxDP &lt;-max(dewpoint)
  minDP &lt;-min(dewpoint)
  DPtrial.seq &lt;-seq(minDP,maxDP,length=3071)
  DPtrial.seq &lt;-data.frame(dewpoint=DPtrial.seq)
  
  #predict only the DP term 
  preds &lt;- predict(gamobj, type=&quot;terms&quot;, newdata=DPtrial.seq, se.fit=TRUE)
  
  #determine confidence intervals
  DPplot &lt;-DPtrial.seq$dewpoint
  fit &lt;-preds$fit
  fit.up95 &lt;-fit-1.96*preds$se.fit
  fit.low95 &lt;-fit+1.96*preds$se.fit
  
  #plot
  plot(DPplot, fit, lwd=3,
   main=&quot;Reconstructed Dew Point Covariate Plot&quot;)
  
  #plot confident intervals
  polygon(c(DPplot, rev(DPplot)), 
      c(fit.low95,rev(fit.up95)), col=&quot;grey&quot;,
      border=NA)
  
  lines(DPplot, fit,  lwd=2)
  rug(dewpoint) 
  </code></pre>
  <p>Reconstructed Dew Point Covariate Plot
  <a href="https://imgur.com/VS8QEcp" rel="nofollow noreferrer">https://imgur.com/VS8QEcp</a></p>
  <h1>ATTEMPT 3 -- changed y-axis using &quot;fitted&quot; but without taking intercept into account</h1>
  <pre><code>plot(dewpoint,fitted(gamobj), main=&quot;Fitted Response of Y (Visibility) Plotted Against Dew Point&quot;)
  abline(h=mean(visibility))
  rug(dewpoint)
  </code></pre>
  <p>Fitted Response of Y Plotted Against Dew Point <a href="https://imgur.com/RO0q6Vw" rel="nofollow noreferrer">https://imgur.com/RO0q6Vw</a></p>
  <p>Ultimately, I want a horizontal line where I can investigate the predictor variable relative to 400 meters, rather than just the mean of the response variable. This way, it will be comparable across multiple sites where the mean visibility is different. Most importantly, it needs to be for multiple covariates!</p>
  <p>Gavin Simpson has explained the method in a couple of posts but unfortunately, I really don't understand how I would hold the mean of the other covariates constant as I use the predict function:</p>
  <p><a href="https://stackoverflow.com/questions/15764810/changing-the-y-axis-of-default-plot-gam-graphs">Changing the Y axis of default plot.gam graphs</a></p>
  <p>Any deeper explanation into the method for doing this would be super helpful!!!</p>