...and attachement...

r, m

-----Original Message-----
From: r-sig-geo-boun...@r-project.org [mailto:r-sig-geo-boun...@r-project.org] 
On Behalf Of Matevž Pavlič
Sent: Monday, July 18, 2011 8:47 AM
To: r-sig-geo@r-project.org
Subject: Re: [R-sig-Geo] predict() LDL error

Hi Edzer, thanks for the help, 

i managed to use the predict() function now. But when I try to plot the 
predictions using spplot() i get this error :

"Error in parse(text = x) : <text>:1:3: unexpected symbol 1: 0.pred" 

Where 0.pred is the the prediction to plot. 

Does anyone has any ideas to what this could mean? I've searcehd the forum, but 
failed to get any answers. 

(attached is the code I use).

Thanks for  your time, m

-----Original Message-----
From: r-sig-geo-boun...@r-project.org [mailto:r-sig-geo-boun...@r-project.org] 
On Behalf Of Edzer Pebesma
Sent: Friday, July 15, 2011 11:15 AM
To: r-sig-geo@r-project.org
Subject: Re: [R-sig-Geo] predict() LDL error

to remove duplicates in DF you need to replace it:

DF = remove.duplicates(DF, zero=0, remove.second = TRUE)
zerodist(DF)

On 07/15/2011 10:23 AM, Matevž Pavlič wrote:
> Hi, thanks for your time....
> 
> I am sure the problem is in same locations...but i dont know why 
> remove.duplicates() does not remove duplicates... 
> When i try this :
> 
>> coordinates(DF)<-~X+Y
>> zerodist(DF)
>      [,1] [,2]
> [1,]   83   84
> [2,]  242  243
> [3,]  266  267
> [4,]  431  432
> [5,]  439  440
> [6,]  731  732
> [7,]  817  818
> [8,]  820  821
> 
>> remove.duplicates(DF, zero=0, remove.second = TRUE)
> ...
> 1113 (99447.1, 459012)     7019   290.17   286.57      6
> 1114 (99465.2, 458975)     7022   291.97   287.27      0
> 1115   (99410, 458997)     7015   291.04   288.74      6
> 1116   (99495, 458978)     7016   290.62   288.72      6
> 1117 (99438.3, 458992)     7018   291.28   288.38      6
> 1118   (99813, 458891)     7021   290.08   285.58      0
> 
>> zerodist(DF)
>      [,1] [,2]
> [1,]   83   84
> [2,]  242  243
> [3,]  266  267
> [4,]  431  432
> [5,]  439  440
> [6,]  731  732
> [7,]  817  818
> [8,]  820  821
> 
> it stays the same...shouln't it remove the duplicates?
> 
> 
> thanks, m
> 
> -----Original Message-----
> From: r-sig-geo-boun...@r-project.org 
> [mailto:r-sig-geo-boun...@r-project.org] On Behalf Of Edzer Pebesma
> Sent: Thursday, July 14, 2011 11:25 PM
> To: r-sig-geo@r-project.org
> Subject: Re: [R-sig-Geo] predict() LDL error
> 
> The error message is an indication that you're predicting (kriging) with a 
> singular covariance matrix. The most frequent reasons for this are duplicate 
> observations [1] or perfect correlation in the coregionalization model [2]. 
> For [1], see ?remove.duplicates, for [2] see argument correct.diagonal in 
> ?fit.lmc.
> 
> On 07/14/2011 06:18 PM, Matevž Pavlič wrote:
>> Hi all,
>>
>>  
>>
>> i am trying to use categorical kriging for prediction of soil classes in an 
>> area. I am pretty new to using cat. kriging in R soI probably am making some 
>> beginers mistakes. Attached is a reproducable sample with sample data. 
>>
>>  
>>
>> When i try to use predict() i geta n error- I am pretty sure because some 
>> points are duplicated....in krige() function i use zerodist() which 
>> eliminates the LDL error, but i can't find a way to use it here....
>>
>>  
>>
>> I got this code (mostly) from the net, so i have some trouble understanding 
>> it...
>>
>>  
>>
>> thanks for any help and info about categorical kriging,
>>
>>  
>>
>> m
>>
>>  
>>
>>
>>
>>
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 
> --
> Edzer Pebesma
> Institute for Geoinformatics (ifgi), University of Münster Weseler Straße 
> 253, 48151 Münster, Germany. Phone: +49 251 8333081, Fax: +49 251 8339763  
> http://ifgi.uni-muenster.de
> http://www.52north.org/geostatistics      e.pebe...@wwu.de
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

--
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster Weseler Straße 253, 
48151 Münster, Germany. Phone: +49 251 8333081, Fax: +49 251 8339763  
http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics      e.pebe...@wwu.de

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
setwd("C:/Users/mpavlic/Documents/2-STUDIJ/9-Analiza/2-v2/Kategoricni kriging")
remove(list=ls())

library(lattice)
library(rgdal)
library(sqldf)
library(gstat)
library(sp)


##### LOAD DATA
DF<-read.csv("zerodist.csv", dec=".", sep=";")
DF$SoilID<-as.factor(DF$SoilID)
str(DF$SoilID)
coordinates(DF)<-~X+Y
zerodist(DF)
DF<-remove.duplicates(DF, zero=0, remove.second = TRUE)
zerodist(DF)
write.table(DF, "zerodist1.csv", sep=";", dec=".")
DF<-read.csv("zerodist1.csv", dec=".", sep=";")
DF$SoilID<-as.factor(DF$SoilID)
str(DF)

##### create table of SoilID
Soil.table<-table(DF [, "SoilID"])
Soil.table

lvls<-levels(DF[,"SoilID"])
print(lvls)


##### CREATE GSTAT OBJECT -3 classes
dat.c <- gstat(id = lvls[1], formula = I(SoilID == lvls[1]) ~ 1, loc=~X+Y, data 
= DF, nmax = 100, set = list(order = 2, zero = 0.01))
dat.c <- gstat(dat.c, lvls[2], I(SoilID == lvls[2]) ~ 1, ~X + Y, DF, nmax = 100)
dat.c <- gstat(dat.c, lvls[3], I(SoilID == lvls[3]) ~ 1, ~X + Y, DF, nmax = 100)


##### fit variogram
dat.c <- gstat(dat.c, model = vgm(1, "Cir", 1200, 1), fill.all = T)
x <- variogram(dat.c)

##### fit lmc
dat.fit = fit.lmc(x, dat.c, fit.ranges=F, fit.sills=c(T,T,T))
plot(x, model = dat.fit)


##### CREATE PREDICTION GRID #####
GridRes<-100
coordinates(DF)<-~X+Y
x.range <- as.integer(range(DF@coords[,1]))
y.range <- as.integer(range(DF@coords[,2]))
str(x.range)

grd<-expand.grid(x=seq(from=x.range[1], to=x.range[2], by=GridRes),
y=seq(from=y.range[1], to=y.range[2], by=GridRes))
coordinates(grd)<-~x+y
gridded(grd)<-T


##### MAKE SURE THE GRID AND POINTS HAVE SAME COORDINATE NAMES
dimnames(coordinates(DF))
dimnames(coordinates(grd))
dimnames(grd@coords) <-list(NULL,c("X", "Y"))
dimnames(grd@bbox) <-list(c("X", "Y"))

##### PREDICT #####
z<-predict(dat.fit, newdata=grd)
str(z)

##### PLOT THE PREDICTION ---> "Error in parse(text = x) : <text>:1:3: 
unexpected symbol 1: 0.pred"

print(spplot(z, zcol="0.pred"), col.regions=terrain.colors(64), contour=T, 
pretty=T, cuts=8, key.space="right")
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to