[R-sig-Geo] predict() LDL error

Matevž Pavlič matevz.pavlic at gi-zrmk.si
Mon Jul 18 21:16:59 CEST 2011


Hi all, 

 

ok i managed to create a prediction with predict() (with gstat object). 

However, what i get now is a set of predictions and covariances grids for each class. Which is great of course, but what i would really like is to create a map of these classes.

I suppose the maximum value of the prediction on the cell would do, but i can not find a way to make these work. I would need to create a code that would check which value of these predictions (clasess) is the greatest for each cell and set this cell to have a name of the predicted class. 

Attached is simplified output of the prediction, where ena.pred, dva.pred, tri.pred……..devet.pred columns represent the prediction (probability) and columns X and Y represent coordinates. So what i would like to do is to generate a code that would check which value is the greates in each X and Y coordinates and assign the name of that column (prediction)

 

I hope I explained it ok, if not i'll try more…

Thanks for the hlep, 

 

m

From: romunov at gmail.com [mailto:romunov at gmail.com] On Behalf Of Roman Luštrik
Sent: Monday, July 18, 2011 11:21 AM
To: Matevž Pavlič
Subject: Re: [R-sig-Geo] predict() LDL error

 

Oj,

 

pred časom smo ustanovili lokalno skupino za R, poimenovana Rkoholiki. Navadno se sestajamo v Ljubljani (oddelek za biologijo). Sicer je čez poletje bolj počasno, je pa v času ne-dopustov kar živahno s srečanji. V kolikor bi te zanimalo, se nam lahko pridružiš na http://groups.google.com/group/rkoholiki kamor obešamo informacije o druženjih in podobno.

 

lp,

Roman

 

 

 

On Mon, Jul 18, 2011 at 11:05 AM, Matevž Pavlič <matevz.pavlic at gi-zrmk.si> wrote:

Hi,



thanks for the help. I renamed it to letters and it works perfectly now.



Thanks again for your time, m




From: caspar hallmann [mailto:caspar.hallmann at gmail.com]

Sent: Monday, July 18, 2011 9:44 AM
To: Matevž Pavlič
Cc: r-sig-geo at r-project.org

Subject: Re: [R-sig-Geo] predict() LDL error



ah...

I think it has to do with the names. Try renaming your columns so that they dont start with a number but rather a character.



names(z)<-paste(letters[1:ncol(z)],names=z,sep="_")

print(spplot(z, zcol=grep("0.pred",z)), col.regions=terrain.colors(64), contour=T, pretty=T, cuts=8, key.space="right")

hope it helps



Caspar



On Mon, Jul 18, 2011 at 9:27 AM, Matevž Pavlič <matevz.pavlic at gi-zrmk.si> wrote:

Hi Caspar,



still get the same error. The str(z) shows this info :



> str(z)

Formal class 'SpatialPixelsDataFrame' [package "sp"] with 7 slots

 ..@ data       :'data.frame': 8736 obs. of  9 variables:

 .. ..$ 0.pred : num [1:8736] 0.174 0.174 0.174 0.174 0.176 ...

 .. ..$ 0.var  : num [1:8736] 0.236 0.236 0.236 0.236 0.236 ...

 .. ..$ 1.pred : num [1:8736] 0.134 0.134 0.134 0.134 0.117 ...

 .. ..$ 1.var  : num [1:8736] 0.136 0.136 0.136 0.136 0.136 ...

 .. ..$ 2.pred : num [1:8736] 0.233 0.233 0.233 0.233 0.234 ...

 .. ..$ 2.var  : num [1:8736] 0.0613 0.0613 0.0613 0.0613 0.0613 ...

 .. ..$ cov.0.1: num [1:8736] -0.0509 -0.0509 -0.0509 -0.0509 -0.0509 ...

 .. ..$ cov.0.2: num [1:8736] -0.0171 -0.0171 -0.0171 -0.0171 -0.0171 ...

 .. ..$ cov.1.2: num [1:8736] -0.0164 -0.0164 -0.0164 -0.0164 -0.0164 ... > str(z)

...



But when i use :


> print(spplot(z, zcol=which(names(z)=="0.pred")), col.regions=terrain.colors(64), contour=T, pretty=T, cuts=8, key.space="right")




i get the same error :


Error in parse(text = x) : <text>:1:3: unexpected symbol

1: 0.pred

   ^



thanks for help,m



From: caspar hallmann [mailto:caspar.hallmann at gmail.com]
Sent: Monday, July 18, 2011 8:58 AM
To: Matev¾ Pavliè

Subject: Re: [R-sig-Geo] predict() LDL error




Hi Matev¾




try:



print(spplot(z, zcol=which(names(z)=="0.pred")), col.regions=terrain.colors(64), contour=T, pretty=T, cuts=8, key.space="right")



Greets



Caspar





2011/7/18 Matev¾ Pavliè <matevz.pavlic at gi-zrmk.si>

...and attachement...

r, m


-----Original Message-----

From: r-sig-geo-bounces at r-project.org [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of Matev¾ Pavliè
Sent: Monday, July 18, 2011 8:47 AM
To: r-sig-geo at 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-bounces at r-project.org [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of Edzer Pebesma
Sent: Friday, July 15, 2011 11:15 AM
To: r-sig-geo at 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-bounces at r-project.org
> [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of Edzer Pebesma
> Sent: Thursday, July 14, 2011 11:25 PM
> To: r-sig-geo at 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 at 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 <tel:%2B49%20251%208333081>  <tel:%2B49%20251%208333081> , Fax: +49 251 8339763 <tel:%2B49%20251%208339763>  <tel:%2B49%20251%208339763>   http://ifgi.uni-muenster.de <http://ifgi.uni-muenster.de/>  <http://ifgi.uni-muenster.de/>


> http://www.52north.org/geostatistics      e.pebesma at wwu.de
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at 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 <tel:%2B49%20251%208333081>  <tel:%2B49%20251%208333081> , Fax: +49 251 8339763 <tel:%2B49%20251%208339763>  <tel:%2B49%20251%208339763>   http://ifgi.uni-muenster.de <http://ifgi.uni-muenster.de/>  <http://ifgi.uni-muenster.de/>


http://www.52north.org/geostatistics      e.pebesma at wwu.de

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

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


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





      [[alternative HTML version deleted]]


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




       [[alternative HTML version deleted]]


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




-- 
In God we trust, all others bring data.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20110718/7fd0bc7e/attachment.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: catK_result.txt
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20110718/7fd0bc7e/attachment.txt>


More information about the R-sig-Geo mailing list