On 24.09.2010 17:51, Annalaura wrote:

Hi, I need help!
I am trying to iterate an iterative process to do cross vadation and store
the results each time.
I have a Spatial data.frame, called Tmese

str(Tmese)
Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots
   ..@ data       :'data.frame': 14 obs. of  17 variables:
   .. ..$ ID      : int [1:14] 73 68 49 62 51 79 69 77 57 53 ...
   .. ..$ Stazione: Factor w/ 29 levels "ALIANO","BONIFATI",..: 2 3 4 5 10 11
12 16 17 19 ...
   .. ..$ X01_1994: num [1:14] 9.34 10.67 5.29 11.86 9.15 ...
   .. ..$ X01_1995: num [1:14] 7.07 9.22 2.32 9.3 6.66 ...
   .. ..$ X01_1996: num [1:14] 9.41 10.4 5.99 12.3 9.93 ...
   .. ..$ X01_1997: num [1:14] 10.67 10.65 5.76 12.82 10.1 ...
   .. ..$ X01_1998: num [1:14] 9.57 10.12 4.44 10.34 8.97 ...
   .. ..$ X01_1999: num [1:14] 8.96 10.21 3.23 10.83 7.74 ...
   .. ..$ X01_2000: num [1:14] 6.58 8.46 2.8 8.37 6.55 ...

Now I want to do 14 cross validation and I wrote a function

idw.cv<- function(x){
tmp<- krige.cv(x~1, Tmese, model=NULL)
return(tmp)
}

But when I run it, it doesn't work, it says:
cv_1994<- idw.cv(X01_1994)


Actually this means that you want to pass an object called "X01_1994" to the function rather than a symbol for the formula.

What you could do in order to stay with the formula notation is to write your own generic / methods that handles different kinds of input including formulae and handle them.

Otherwise a quick and dirty approach (with some shortcomings) for example is:

idw.cv<- function(x){
form <- as.formula(paste(x, "~1"))
tmp<- krige.cv(form, Tmese, model=NULL)
return(tmp)
}

cv_1994<- idw.cv("X01_1994")

Uwe Ligges




Error in eval(expr, envir, enclos) : object 'X01_1994' not found

Why????Please Help me!





______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to