[GRASS-stats] help coding an anova using raster data

Roger Bivand Roger.Bivand at nhh.no
Fri Nov 21 18:36:36 EST 2008


On Fri, 21 Nov 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?

No, it doesn't. Each raster given the current region in GRASS has an equal 
number of cells, so all of the rasters you move to R have the same size 
and resolution. You asked the rep* to be treated as factors - did you do 
summary(SGDF) to see what is inside? The term "a repetition" isn' clear at 
all - are these plot masks or what?

Roger

> Thanks,
> Sam
>
>
> 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
>>> 
>>> 
>> 
>
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the grass-stats mailing list