Summing columns for habitat selection test

I am doing a habitat selection test using chi square and I need to lump habitats that have an expected value under 5, I've found which those are but I can't figure out how to combine the observed and proportion data for those. I need to combine value 4,6,7,8 and 9 into one value. Please help!

Observed=c(181,132,96,20,168,86,105,313,206),
Proportion=c(0.5005,0.3389,0.0667,0.0031,0.0338,0.0225,0.0067,0.0116,0.0162)

I do not understand your data. The Observed values seem unrelated to the Proportion values. For example the first values in each vector are 181 and 0.5005 and the last values are 206 and 0.0162. Those proportions are obviously not the proportion of the listed observations. What are they? You also want to combine observations when the expected value is less than five but all of your observations are well over five. Can you explain more about your data?

The observed is the amount of times an animal was observed in a certain habitat and the proportion is the proportion that habitat takes up for the entire landscape. From these I am doing a chi square test but some values are too small and so I need to combine the row 4,6,7,8,9 so they make up an “other” habitat and I can run my chi square again.

Is this the sort of thing you are looking for? I am guessing that the product of the Observed and the Proportion gives you a predicted number of counts and you want to combine all cases where the predicted number of counts is less than 5. The total number of predicted counts is preserved.

Observed=c(181,132,96,20,168,86,105,313,206)
Proportion=c(0.5005,0.3389,0.0667,0.0031,0.0338,0.0225,0.0067,0.0116,0.0162)

PredCounts <- Observed * Proportion
PredCounts
#> [1] 90.5905 44.7348  6.4032  0.0620  5.6784  1.9350  0.7035  3.6308  3.3372
sum(PredCounts)
#> [1] 157.0754

ObsMod <- c(Observed[1], Observed[2], Observed[3], 
            sum(Observed[4], Observed[6], Observed[7], Observed[8], Observed[9]),
            Observed[5])

PropMod <- c(Proportion[1], Proportion[2], Proportion[3], 
            sum(Proportion[4], Proportion[6], Proportion[7], Proportion[8], Proportion[9]),
            Proportion[5])
PredCountsMod <- ObsMod * PropMod
PredCountsMod
#> [1] 90.5905 44.7348  6.4032 43.8730  5.6784
sum(PredCounts)
#> [1] 157.0754

Created on 2020-11-21 by the reprex package (v0.3.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.