I am kind of new with statistics. I have two raster with categorical values and I want to get chi-square. How can I do this using R? Rasters have the same region and same resolution. Is chi-square the right choice for the computation of variance by ranks?
It seems to be a question not so related to GIS, that is since you are treating the raster as a "list" (or a vector) of values. Anyhow you can use the following workflow in R: Assume you have raster objects called r1 and r2.
>r1Vals<-getValues(r1);r2Vals<-getValues(r2) # Extract values of r1 and r2 cells to verctors >r1Vals<-as.facotr(r1Vals);r2Vals<-as.factor(r2Vals) # Convert values to factor (categorial) >chisq(r1,r2) # Preforms Pearson's chi-square test
I suggest further reading on thge r functions: getValues of the raster package; chisq of the stats package; and the factor object from the base package. In addition - it is reccomended to get help about the right statistical test and its validity to your data in Cross-Validate foroum.