Professional Documents
Culture Documents
Norwegian Spruces - Main Effects and Interaction: 1 Model
Norwegian Spruces - Main Effects and Interaction: 1 Model
Norwegian Spruces - Main Effects and Interaction: 1 Model
Ege
September 5, 2011
1 Model
In this document we use the following model:
X X X
λ(x, r; Hr ) = exp(κ(r)) exp[−θ1 kx−xi kα −θ2 (ri −r)β −θ3 kx−xi kα (ri −r)β ]I[r+ri < kxi −xk for
i:ri >r i:ri >r i:ri >r
> data(spruces)
> Y <- spruces
> Y <- Y %mark% (marks(Y)/2)
1
> dtimes <- 10
> nbreaks <- 10
> HIST <- "greater"
> alphavec <- -c(2, 3, 4)
> betavec <- c(0, 0.001, 0.1, 0.5)
> phigen <- function(alpha, beta) {
+ phi <- function(dx, mx, mu) {
+ dt <- mx - mu
+ rslt <- c(-dx^alpha, -dt^beta, -dx^alpha * dt^beta)
+ rslt[dx < mx + mu] <- -Inf
+ rslt
+ }
+ return(phi)
+ }
> nphi <- length(phigen(1, 1)(1, 1, 1))
To define the model we need the breakpoints for the piecewise constant mark
intensity. Here we just use nbreaks intervals of the same size covering the mark
range.
[1] 10
Next we make a data frame with different values of α and β and fit the model
for each pair of values. The fitted parameter values and the log-likelihood value
is recorded in the data frame as well and the results are saved for later model
checking.
> alphavec
[1] -2 -3 -4
> betavec
2
> kappa <- data.frame(matrix(-Inf, N, nbreaks))
> theta <- data.frame(matrix(0, N, nphi))
> for (i in 1:nbreaks) {
+ names(kappa)[i] <- paste("kappa.", i, sep = "")
+ }
> for (i in 1:nphi) {
+ names(theta)[i] <- paste("theta.", i, sep = "")
+ }
> dat <- cbind(dat, L = 0, theta, kappa, poismean = 0, converged = FALSE)
> vcovList <- vector("list", N)
> timestart <- proc.time()[1]
> Q <- quadscheme.spacetime(Y, default.dummy(Y, nd = ND), dummytimes = dtimes)
> Q
Quadrature scheme
134 data points, 76368 dummy points
Total weight 223.44
> for (i in 1:N) {
+ phi <- phigen(dat$alpha[i], dat$beta[i])
+ fit <- ppm(Q, ~fn(marks) - 1, GM3(phi, HIST), correction = "none")
+ dat$L[i] <- fit$maxlogpl
+ glmfit <- getglmfit(fit)
+ dat$converged <- glmfit$converged
+ vcovList[[i]] <- vcov(glmfit)
+ coeff <- fit$coef
+ coefname <- names(coeff)
+ theta <- coeff[substr(coefname, 1, 5) == "Inter"]
+ kappaindex <- substr(coefname, 1, 5) != "Inter"
+ kappaname <- coefname[kappaindex]
+ kappaname <- paste("kappa", substr(kappaname, 10, nchar(kappaname)), sep = ".")
+ kappa <- coeff[kappaindex]
+ datname <- substr(names(dat), 1, 5)
+ dat[i, kappaname] <- kappa
+ dat[i, datname == "theta"] <- theta
+ dat$poismean[i] <- sum(exp(dat[i, datname == "kappa"]) * volume)
+ rm(fit)
+ }
> runtime <- proc.time()[1] - timestart
> runtime
user.self
161.286
Now we make sure the fitted model does not involve too big a thinning.
> index <- which.max(dat$L)
> alpha <- dat$alpha[index]
3
> beta <- dat$beta[index]
> phi <- phigen(alpha, beta)
> kappa <- as.numeric(dat[index, datname == "kappa"])
> theta <- as.numeric(dat[index, datname == "theta"])
> simList <- replicate(nsim, ppp(x = numeric(0), y = numeric(0), window = Y$window), simplif
> timestart <- proc.time()[1]
> if (dat$poismean[index] <= maxpoismean) {
+ for (i in 1:nsim) {
+ simList[[i]] <- piecewisepois(markbreaks, kappa, Y$window)
+ cat(proc.time()[1] - timestart)
+ simList[[i]] <- thin(simList[[i]], phi, theta, output = 1)
+ if (i == nsim)
+ cat("\n")
+ }
+ }
00.7441.4442.1682.9243.744.465.1845.908