File: trwlgam1.q

package info (click to toggle)
sm 2.2-6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,540 kB
  • sloc: f90: 259; ansic: 21; makefile: 2
file content (25 lines) | stat: -rw-r--r-- 822 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
library(gam)
ind       <- (trawl$Year == 0 & trawl$Zone == 1)
score1    <- trawl$Score1[ind]
latitude  <- trawl$Latitude[ind]
longitude <- trawl$Longitude[ind] - 143
position  <- cbind(latitude, longitude = -longitude)

par(mfrow = c(2,2))
par(cex=0.7)
model1  <- sm.regression(position, score1, h = c(0.1, 0.1))
model2  <- gam(score1 ~ lo(latitude) + lo(longitude))
ex      <- model1$eval.points[,1]
ey      <- model1$eval.points[,2]
ngrid   <- length(ex)
grid    <- data.frame(cbind(latitude = rep(ex, ngrid),
            longitude = rep(-ey, rep(ngrid, ngrid))))
surface <- predict(model2, grid)
mask    <- model1$estimate
mask[!is.na(mask)] <- 1
persp(ex, ey, matrix(surface * mask, ncol = ngrid),
            xlab = "latitude", ylab = "longitude")
summary(model2)
plot(model2, se=TRUE)
par(cex=1)
par(mfrow = c(1,1))