# NOT RUN {
#
#
#generate observation locations (100 is small just to make this run quickly)
n=100
set.seed(124)
x = matrix(runif(2*n), nrow=n)
#generate observations at the locations
trueTheta = .1
trueSigma = .01
Sigma = exp( -rdist(x,x) /trueTheta )
# y = t(chol(Sigma))%*% (rnorm(n)) + trueSigma * rnorm( n)
y = t(chol(Sigma))%*% (rnorm(n)) + trueSigma * rnorm( n)
# Use exponential covariance estimate constant function for mean
out = MLESpatialProcess(x, y,
smoothness=.5,
mKrig.args = list( m = 1)
)
# Use exponential covariance, use a range to determine MLE of range parameter
# }
# NOT RUN {
#Use Matern covariance, compute joint MLE of range, smoothness, and lambda.
#This may take a few seconds
testSmoothness = c(.5, 1, 2)
for( nu in testSmoothness){
out = MLESpatialProcess(x, y, cov.args=list(Covariance="Matern"), smoothness=nu)
print( out$MLEJoint$summary)
}
# }
# NOT RUN {
# example with a covariate
# }
# NOT RUN {
data(COmonthlyMet)
ind<- !is.na( CO.tmean.MAM.climate)
x<- CO.loc[ind,]
y<- CO.tmean.MAM.climate[ind]
elev<- CO.elev[ind]
obj2<- MLESpatialProcess( x,y)
obj3<- MLESpatialProcess( x,y, Z=elev)
# elevation makes a difference
obj2$MLEJoint$summary
obj3$MLEJoint$summary
# }
# NOT RUN {
# }
# NOT RUN {
# fits for first 10 days from ozone data
data( ozone2)
NDays<- 10
O3MLE<- matrix( NA, nrow= NDays, ncol=7)
for( day in 1: NDays){
cat( day, " ")
ind<- !is.na(ozone2$y[day,] )
x<- ozone2$lon.lat[ind,]
y<- ozone2$y[day,ind]
print( length( y))
O3MLE[day,]<- MLESpatialProcess( x,y,
Distance="rdist.earth")$MLEJoint$summary
}
# NOTE: names of summary:
#[1] "lnProfileLike.FULL" "lambda"
#[3] "theta" "sigmaMLE"
#[5] "rhoMLE" "funEval"
#[7] "gradEval"
plot( log(O3MLE[,2]), log(O3MLE[,3]))
# }
Run the code above in your browser using DataLab