[R] Comparing three groups, data: present, absent

Wu Gong ghowoo at gmail.com
Fri May 21 06:38:14 CEST 2010


## Dung observations
## Create a sample original data
data <- data.frame(Species=sample(c("W", "G", "R"), 200, replace=TRUE),
	Age=sample(c("days", "weeks", "months"),200,replace=TRUE),
	Termites=sample(c(0,1),200,replace=TRUE))

## Show what original data look like
head(data)

  Species    Age Termites
1       W months        0
2       R  weeks        0
3       W  weeks        0
4       G  weeks        0
5       R months        1
6       W   days        1


## Analyze each species 
## Here we just tabulate Waterbuck as an example
data.w <- data[data$Species == "W",]
table.w <- table(data.w[,2:3])

## The results table looks like
table.w
        Termites
Age       0  1
  days   18  9
  months  9 11
  weeks  10 18
  
## Apply Chi-squared Test
chisq.test(table.w)

## Usually use Pearson's Chi-squared Test
## If your data are not suitable for the Pearson's Chi-squared Test, it
seems that R will tell you. 
## H0 : All three age groups have same Termites attack percentage.
## H1 : All situations except H0.

-----
A R learner.
-- 
View this message in context: http://r.789695.n4.nabble.com/Comparing-three-groups-data-present-absent-tp2224751p2225612.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list