[R-sig-Geo] 回复:Re: how to choose best parameters of variogram model in gstat
Jessie Zhang
zhyj830515 at 126.com
Sat Mar 24 15:52:48 CET 2012
Hi Giuseppe Calamita ,
Thank you so much. I will try it soon.
Best regards
Jessie Zhang
--
Dept. of Occupational and Environmental Health
Peking University School of Public Health
38 Xue Yuan Road, Beijing 100191, P.R. China
Tel: +86-10-82805130
Mobile: +86-15210892212
At 2012-03-24 22:45:53,"Giuseppe Calamita [via R-sig-geo]" <ml-node+s2731867n7401439h96 at n2.nabble.com> wrote:
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
If you reply to this email, your message will be added to the discussion below:
http://r-sig-geo.2731867.n2.nabble.com/how-to-choose-best-parameters-of-variogram-model-in-gstat-tp7394459p7401439.html
To unsubscribe from how to choose best parameters of variogram model in gstat, click here.
NAML
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Re-how-to-choose-best-parameters-of-variogram-model-in-gstat-tp7401447p7401447.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
More information about the R-sig-Geo
mailing list