Skip to content
Back to formatted view

Raw Message

Message-ID: <57035F6E.1020408@uni-muenster.de>
Date: 2016-04-05T06:47:10Z
From: Edzer Pebesma
Subject: How to perform 'repeated K-fold cross validation' using gstat package?
In-Reply-To: <Mime4j.3653.847c65750c29ce16.153e4ccec63@gist.ac.kr>

Please don't repeat questions to this list when there is no answer
within 24 hours; there are over 3000 subscribers.

The link you point to demonstrates how to use a for loop to repeat a
certain procedure, such as cross validation. Study it well, and ask
yourself what information you want to retain from each loop iteration,
and what you want to do with it afterwards.

On 05/04/16 07:02, uzzal at gist.ac.kr wrote:
> By using gstat package, I can do 5-fold cross validation. How can
> I write the code/create the loop for "Repeated 5-fold cross validation"
> for 10 repeat. Code for 5-fold cross validation is given below. I knew
> about 'repeated k-fold cross validation' from here
> <http://stats.stackexchange.com/questions/103459/how-do-i-know-which-method-of-cross-validation-is-best>.
> 
> 
> library(sp)
> data(meuse)  
> coordinates(meuse) <- ~x+y
> m <- vgm(.59, "Sph", 874, .04)
> 
> 
> # five-fold cross validation:
> x <- krige.cv(log(zinc)~1, meuse, m, nmax = 40, nfold=5)
> str(x)
> (R <-cor(x$observed, x$var1.pred))
> (RMSE<- sqrt(mean((x$var1.pred-x$observed)^2)))
> 
> 
> Orpheus
> 
> --------- ?? ?? ---------
> 
>     *????* : <uzzal at gist.ac.kr>
>     *????* : r-sig-geo <r-sig-geo at r-project.org>
>     *????* : 2016? Apr 4?(Mon) 22:02:51
>     *??* : [R-sig-Geo] Is there option for 'repeated K-fold cross
>     validation' in gstat package?
> 
>     I am working with spatial dataset. I have done ordinary kriging on
>     this dataset using gstat package in R. I want to do 'repeated
>     K-fold cross validation' using krige.cv function of gstat package.
>     as far as I know using krige.cv function K-fold/n-fold cross
>     validation is possible. Is there any option of doing 'repeated
>     K-fold cross validation'  in gstat? or K-fold cross validation is
>     enough to check the relation between observed values and kriging
>     predicted values?
> 
> 
>     I came to know about 'repeated K-fold cross validation'  from here.
>     <http://stats.stackexchange.com/questions/103459/how-do-i-know-which-method-of-cross-validation-is-best> Any
>     kind help will be appreciable.
> 
> 
>     Orpheus
> 
>     --------- ?? ?? ---------
> 
>         *????* : Tom Philippi <tephilippi at gmail.com>
>         *????* : Karla Shikev <karlashikev at gmail.com>
>         *??* : r-sig-geo <r-sig-geo at r-project.org>
>         *????* : 2016? Apr 4?(Mon) 05:17:16
>         *??* : Re: [R-sig-Geo] generating object with multiple polygons
> 
>         Karla--
>         If you want a SpatialPolygonsDataFrame with both slices of polygons, you
>         can use spatial rbind.  The issue that may trip you up is that your slice1
>         and slice2 objects might not have unique polygon IDs.  Perhaps the simplest
>         solution is to use the spChFIDs in sp, with some prefix distinguishing
>         slice1 from slice2.  I assume you're generating some attributes as
>         variables in the data frame to distinguish the different polygons; you can
>         use those values as the prefix.  You can google this, or start with:
>         http://www.inside-r.org/packages/cran/sp/docs/as.data.frame.SpatialPolygonsDataFrame
>         http://gis.stackexchange.com/questions/32732/proper-way-to-rbind-spatialpolygonsdataframes-with-identical-polygon-ids
> 
>         Tom 2
> 
>         On Sun, Apr 3, 2016 at 6:53 AM, Karla Shikev wrote: > Dear all, > > This might be a newbie question, so I'd
>         appreciate your patience with this. > > I'm obtaining climatic
>         data from worldclim and generating polygons based on > different
>         climatic limits: > > library(raster) > xx<-getData('worldclim',
>         var='bio', res=10)$bio1 > slice1 <- rasterToPolygons(xx, fun =
>         function(x) {x > 200 & x < 260}) > slice2 <-
>         rasterToPolygons(xx, fun = function(x) {x > 250 & x < 300}) > >
>         Now, I'd like to combine "slice1" and "slice2" into the same >
>         "SpatialPolygonsDataFrame" object, but I do not want to merge
>         them. > > Any help will be greatly appreciated. > > Karla > >
>         [[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
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> 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
Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081
Journal of Statistical Software:   http://www.jstatsoft.org/
Computers & Geosciences:   http://elsevier.com/locate/cageo/
Spatial Statistics Society http://www.spatialstatistics.info

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20160405/ead05212/attachment.bin>