[R] Three-dimensional contingency table

Ista Zahn izahn at psych.rochester.edu
Sun Aug 29 16:06:37 CEST 2010


Hi,
Your example works fine for me. My guess is that you have one of wd,
wv, MP, or Count defined as a global variable. This is the main reason
the use of attach() is discouraged by many people on this list. The
safer thing to do is

model1 <- glm(Count~MP+wd+wv,poisson. data = frame)

-Ista
On Sat, Aug 28, 2010 at 10:58 PM, Randklev, Charles
<CharlesRandklev at my.unt.edu> wrote:
> 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)
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org



More information about the R-help mailing list