[R-sig-Geo] How to apply a local polynomial regression function to a RasterStack object by "calc" function?

Richard Ma xuanlong.ma at uts.edu.au
Mon Aug 22 04:03:55 CEST 2011


Hi all,

I have a RasterStack with 23 layers. Now I want to fit a local polynomial
regression through 23 layers. I use the package "KernSmooth" to fit the
regression function. 

Here is the example data, you can download them from my Dropbox folder, it's
a native raster package format:
http://dl.dropbox.com/u/19228076/cmg_stack.grd
http://dl.dropbox.com/u/19228076/cmg_stack.gri

Here is my code:
#########################################
require(raster)
require(KernSmooth)

cmg.stack <- stack("cmg_stack.grd")

# Calculate the bandwidth for each cell
time <- seq(1, 353, 16)
fun.bw <- function(x) dpill(x, x = time, gridsize = 365)
bw <- calc(cmg.stack, fun.bw)  # This line do works

# Create a function to apply the "locpoly" function
fun.lp <- function(x) {yvalues <- locpoly(x = time, y = x, bandwidth = bw,
gridsize = 365)$y
return(values)}

########################
## However, I got an error:
########################

> cmg.stack.lp <- calc(cmg.stack, fun.lp, progress = "text")
Error in .local(x, fun, ...) : cannot use this function

#########################################

Can you please point my problem? Is that possible to apply this function by
"calc"? Or are there any other solution to my question?

Thanks in advance for any help.

Sincerely,
Richard

-----
Richard Ma
PhD student, Ecology & Remote Sensing
Climate Change Cluster, Department of Environment Science
University of Technology, Sydney
http://everydropr.wordpress.com
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/How-to-apply-a-local-polynomial-regression-function-to-a-RasterStack-object-by-calc-function-tp6709955p6709955.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list