[GRASS-stats] help coding an anova using raster data
Sam Veloz
sdveloz at ucdavis.edu
Sun Nov 23 14:33:00 EST 2008
Thanks, stack and reshape are what I needed.
Sam
Dylan Beaudette wrote:
> On Friday 21 November 2008, Sam Veloz wrote:
>> When I tried this:
>> test.aov <- aov(response ~ ., data=SGDF)
>> It only gives the next variable in the resulting ANOVA table.
>>
>> The other option you gave:
>> test.aov <- aov(response ~ rep1 + rep2 + rep3 + rep4 + rep5, data=SGDF)
>>
>> doesn't work because it treats each "rep" as a factor, I would like each
>> of these rasters to be a repetition. In other words I would have an n of
>> 5. Does this make sense?
>> Thanks,
>> Sam
>
> In that case you need to 'stack' your data into long format. check the mailing
> list for ideas. Functions of interest:
>
> stack()
> reshape()
>
> and the 'reshape' package
>
> Cheers,
>
> Dylan
>
>
>> Roger Bivand wrote:
>>> On Thu, 20 Nov 2008, Sam Veloz wrote:
>>>> I would like to run an anova on a set of raster variables imported
>>>> from GRASS into R but am confused about how R handles the raster data.
>>>> So if I have a model with a treatment with 2 levels, each raster is a
>>>> binary file with cells coded for each level of the treatment. I have 1
>>>> response raster layer that corresponds spatially with the treatment
>>>> layers. So let's say I have 5 rasters representing a different rep of
>>>> the treatment how would I code this in R? I started out trying this:
>>>>
>>>> treatment<-readRAST6(c("rep1","rep2","rep3","rep4","rep5"),cat=TRUE)
>>>> response<-readRAST6("response",cat=FALSE)
>>>> test.aov<-aov(response~treatment)
>>> The objects returned by readRAST6 are SpatialGridDataFrames. I think
>>> that you may find that:
>>>
>>> SGDF <- readRAST6(c("rep1", "rep2", "rep3", "rep4", "rep5", "response"),
>>> cat=c(TRUE, TRUE, TRUE, TRUE, TRUE, FALSE))
>>> test.aov <- aov(response ~ ., data=SGDF)
>>>
>>> does the trick (the . inserts the remaining variables) - or safer:
>>>
>>> test.aov <- aov(response ~ rep1 + rep2 + rep3 + rep4 + rep5, data=SGDF)
>>>
>>> Untried.
>>>
>>> By the way, do you need aov(), or would anova(lm()) do the same? I guess
>>> the richer setting needs facilities in aov() that aren't visible here.
>>>
>>> Hope this helps,
>>>
>>> Roger
>>>
>>>> but I don't think this is right. Is it possible to do what I am
>>>> trying? My data is actually a bit more complicated than this but if I
>>>> can clear this up than I think I can do the rest on my own.
>>>> Thanks for your help,
>>>> Sam
>
>
>
--
****************************************************
Sam Veloz
Postdoctoral Researcher
Department of Environmental Science and Policy
University of California, Davis
sdveloz at ucdavis.edu
More information about the grass-stats
mailing list