[R] Three-dimensional contingency table

Randklev, Charles CharlesRandklev at my.unt.edu
Sun Aug 29 04:58:59 CEST 2010


Hi,

I am trying to assemble a three-way contingency table examining the presence/absence of mussels, water depth (Depth1 and Depth 2) and water velocity (Flow vs. No Flow). I have written the following code listed below; however, when run the glm I get the following message, "Error in model.frame.default(formula = Count ~ MP + wd + wv, drop.unused.levels = TRUE) : variable lengths differ (found for 'MP')". This may be something simple, if so I apologize. Any help would be greatly appreciated.

Best,
C.R.

numbers <- c(1134,956,328,529,435,599,27,99)
dim(numbers) <- c(2,2,2)
numbers
dimnames(numbers)[[3]] <-list("Mussels", "No Mussels")
dimnames(numbers)[[2]] <- list("Flow", "No Flow")
dimnames(numbers)[[1]] <- list("Depth1", "Depth2")
ftable(numbers)
as.data.frame.table(numbers)
frame <- as.data.frame.table(numbers)
names(frame) <- c("wd", "wv", "MP", "Count")
frame
attach(frame)
model1 <- glm(Count~MP+wd+wv,poisson)


More information about the R-help mailing list