File: trwlgam3.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 (31 lines) | stat: -rw-r--r-- 999 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
26
27
28
29
30
31
library(gam)
with(trawl, {
ind       <- (Year == 0 & Zone == 1)
score1    <- Score1[ind]
latitude  <- Latitude[ind]
longitude <- Longitude[ind] - 143
position  <- cbind(latitude, longitude = -longitude)

model1 <- gam(score1 ~ lo(longitude) + lo(latitude))
model2 <- gam(score1 ~ lo(longitude) +    latitude)
model3 <- gam(score1 ~ lo(longitude))
print(anova(model1))
print(anova(model2, model1))
print(anova(model3, model2))

par(mfrow = c(1,2))
model4  <- sm.regression(position, score1, h = c(0.1, 0.1),
              display = "none")
ex      <- model4$eval.points[,1]
ey      <- model4$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    <- model4$estimate
mask[!is.na(mask)] <- 1
persp(ex, ey, matrix(surface * mask, ncol = ngrid),
              xlab = "Latitude", ylab = "Longitude")
sm.regression(position, score1, h = c(100, 0.1))
par(mfrow=c(1,1))
})