[R-sig-eco] Problem with GAM

Gavin Simpson gavin.simpson at ucl.ac.uk
Thu Jun 2 18:16:15 CEST 2011


On Thu, 2011-06-02 at 15:55 +0100, momadou sow wrote:
> Hi, 
> I used GAM function with this code: 
> 
> library(mgcv)
> modgam=gam(Z~X+Y,data=table)
> vis.gam(modgam,view=c("X","Y"),plot.type="contour",zlim=c(1,16))
> 
> My problem is on my figure, the predicted values begin by 0 until 16 with an
> interval equal 2:
> 1- I want that the predicted values (Z) begin by 1 until 16 with an interval
> equal 1. I tried with zlim=c(1,16) but the result is not good. How do I do it?

Read ?vis.gam more carefully and note what is said about the `...`
argument for passing arguments on to, in this case, `contour()`. Take a
look at `?contour` and 

library(mgcv)
set.seed(0)
n<-200;sig2<-4
x0 <- runif(n, 0, 1);x1 <- runif(n, 0, 1)
x2 <- runif(n, 0, 1)
y<-x0^2+x1*x2 +runif(n,-0.3,0.3)
g<-gam(y~s(x0,x1,x2))

## compare default with user-selected levels:
layout(matrix(1:2, ncol = 2))
vis.gam(g, view=c("x1","x2"), plot.type="contour")
vis.gam(g, view=c("x1","x2"), plot.type="contour", levels = seq(0.35,
1.15, by = 0.1))
layout(1)

(Ignore the warnings)

> 2- On the figure, the red color corresponds with the weak values and light red
> corresponds with the big values. How to invert the color to obtain red color
> corresponding with the big values.

I think there is something else going on here - if you are displaying
the fitted model with +/- standard errors, which can't be done on a
contour plot - vis.gam issues a warning and switches to plotting via
`persp()`. If you meant change the colours on the `persp()` plot then I
think you are out of luck as the hi and lo colours are hard coded in the
function.

>  
> Note: I apologize
> for my bad English
> Thanks for your help.
> Madou

HTH

G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-sig-ecology mailing list