I am trying to create basic descriptive statistics for a spatial dataset using moving windows of variable sizes. I found the filter(dataset, rep(1/a,1)) very useful for obtaining averages for a given moving window size "a" (a is the window size within a column of data in a matrix - the filter is applied to all columns automatically) I could not find anything analogous for calculating variances over a moving window. Is there one available? Otherwise, I'm slowly cranking away on making my own, but it's quite tedious! Thank you in advance for any insights! -Philippe
hi: use the fact that Var(x) = E(x^2) - E(x)^2 so that you can still use moments just like you did for the mean. On Thu, Oct 21, 2010 at 5:30 PM, Philippe Hensel <Philippe.Hensel@noaa.gov>wrote:> I am trying to create basic descriptive statistics for a spatial dataset > using moving windows of variable sizes. > > I found the filter(dataset, rep(1/a,1)) very useful for obtaining averages > for a given moving window size "a" > (a is the window size within a column of data in a matrix - the filter is > applied to all columns automatically) > > I could not find anything analogous for calculating variances over a moving > window. Is there one available? > Otherwise, I'm slowly cranking away on making my own, but it's quite > tedious! > > Thank you in advance for any insights! > > -Philippe > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
On Thu, Oct 21, 2010 at 5:30 PM, Philippe Hensel <Philippe.Hensel at noaa.gov> wrote:> I am trying to create basic descriptive statistics for a spatial dataset > using moving windows of variable sizes. > > I found the filter(dataset, rep(1/a,1)) very useful for obtaining averages > for a given moving window size "a" > (a is the window size within a column of data in a matrix - the filter is > applied to all columns automatically) > > I could not find anything analogous for calculating variances over a moving > window. ?Is there one available? > Otherwise, I'm slowly cranking away on making my own, but it's quite > tedious! >rollapply in the zoo package can take an arbitrary R function. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com