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

6 messages Options
Embed this post
Permalink
Sam Veloz

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

Reply Threaded More More options
Print post
Permalink
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)

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
[hidden email]
_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats
Roger Bivand

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

Reply Threaded More More options
Print post
Permalink
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: [hidden email]

_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats
Roger Bivand
Economic Geography Section
Department of Economics
Norwegian School of Economics and Business Administration
Helleveien 30
N-5045 Bergen, Norway
Sam Veloz

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

Reply Threaded More More options
Print post
Permalink
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


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
[hidden email]
_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats
Dylan Beaudette

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

Reply Threaded More More options
Print post
Permalink
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



--
Dylan Beaudette
Soil Resource Laboratory
http://casoilresource.lawr.ucdavis.edu/
University of California at Davis
530.754.7341
_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats
Roger Bivand

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

Reply Threaded More More options
Print post
Permalink
In reply to this post by Sam Veloz
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: [hidden email]

_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats
Roger Bivand
Economic Geography Section
Department of Economics
Norwegian School of Economics and Business Administration
Helleveien 30
N-5045 Bergen, Norway
Sam Veloz

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

Reply Threaded More More options
Print post
Permalink
In reply to this post by Dylan Beaudette
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
[hidden email]
_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats