I have a stack of grid files (23) in ASC format from a MODIS sensor and I need to calculate a 90% confidence interval, mean, min, etc, for each one in R, how can I do that? specially the interval.

## set working directory
FilesPath <- "C:/Users/Grettel/ "     
FileList <- list.files()

# Loop for all grids by julian days and create stats
for (i in  unique(substring(FileList,40,42))){



  # Create output directory

  # list files by pattern of julian day
  FilesToRead<-list.files(pattern=paste("*",JulianDay,"*", sep=""))

  # create raster stack

  # mean files
  # min files
  # max files
  # sd files
  sdRaster <-calc(FilesStack, fun = sd) 

  # intervalo confianza
  #CIRaster <- ci(meanRaster, conf.level = 0.9)

  # write new asci into output folder
                             JulianDay, sep=""),
              overwrite=T, "ascii") 
  • Since these seem to be a time series of rasters, you ought to consider assessing the possibility of a significant serial correlation coefficient first, because that would (strongly) affect the confidence intervals. – whuber Aug 28 '14 at 14:38
  • thanks a lot Whuber and yes these are a time series or raster from 2000 to 2014 (EVI) and could you guide me with that, I'm new in R.. I would appreciate it!! – Greta Pura Vida Aug 28 '14 at 14:49
  • 1
    As usual, @whuber provides very solid advice. Confidence intervals on a timeseres will not mean much at all. You can write a function that coerces the raster stack to a ts object and then use the acf function to calculate the serial correlation. Keep in mind that acf returns a autocorrelation coefficient for each lag. Because of this you will have to write output to a raster stack. It is quite important to look at serial autocorrelation across lags and not as a single correlation coefficient. Let me know if you need a "nudge" to get started. – Jeffrey Evans Nov 9 '14 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.