[R-sig-Geo] how to choose best parameters of variogram model in gstat

Giuseppe Calamita calamita_giuseppe at yahoo.it
Sat Mar 24 15:45:53 CET 2012


Hi Jessie Zhang,
I modified your code and the following works ... it will not be the most
elegant solution for sure :) (but I'm not a programmer , just a simply
useR).

# this part was ok
########################################################
library(gstat)
library(automap)
rm(list=ls())
data<-read.csv("sampledata.csv",header=T)
pred.basis<-read.csv("bj.csv",header=T)
data$date<-as.Date(data$date)
day<-unique(data$date)
length<-length(day)
pred.data<-matrix(NA, nrow = length(pred.basis[,1]), ncol=length,
byrow=TRUE,
                  dimnames = list(pred.basis$id,day))
reshape.data<- reshape(data, v.names="pm10", idvar="station",
                       timevar="date", direction="wide")
#########################################################

# I first checked and substituted NAs with the means of the data.frame
coloumn
for(k in 4: 13) {
  for(i in 1:27)   {
  if (is.na(reshape.data[,k][i])) reshape.data[,k][i]=
mean(reshape.data[,k],na.rm=T)
                       }
                    }


#explicit data objects
coordinates(reshape.data)<- ~x+y
coordinates(pred.basis)  <- ~x+y # you forgot to do this in your code


#I guess there were some problems with the names of the variables, so I
decided to use simpler and shorter names without dots

names(reshape.data) #check names
new_names<- NULL  # prepare a vector for storing new names
for(i in 1:10) new_names[i] <- paste("z",i, sep="") #create new names
names(reshape.data)[-1]<- new_names   #assign them to reshape data


#for convenience, I decided to eliminate the station col from the
reshape.data 
stations <- reshape.data at data$station #save stations separately
reshape.data at data$station <- NULL    #erase station coloumn


model.auto <- vector("list", 10) #prepare a list for storing the autokrige
output
for (i in 1:10)  model.auto[[i]]<- autoKrige(reshape.data[,i], pred.basis)

Cheers 

Giuseppe Calamita


--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/how-to-choose-best-parameters-of-variogram-model-in-gstat-tp7394459p7401439.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list