Re: [R] Three-dimensional contingency table

2010-08-29 Thread Ista Zahn
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
charlesrandk...@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@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

__
R-help@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.


Re: [R] Three-dimensional contingency table

2010-08-29 Thread Cheng Peng

I didn't see any error when I ran your code in my computer:

 numbers - c(1134,956,328,529,435,599,27,99) 
 dim(numbers) - c(2,2,2) 
 numbers 
, , 1

 [,1] [,2]
[1,] 1134  328
[2,]  956  529

, , 2

 [,1] [,2]
[1,]  435   27
[2,]  599   99

 dimnames(numbers)[[3]] -list(Mussels, No Mussels) 
 dimnames(numbers)[[2]] - list(Flow, No Flow) 
 dimnames(numbers)[[1]] - list(Depth1, Depth2) 
 ftable(numbers) 
Mussels No Mussels
  
Depth1 Flow1134435
   No Flow  328 27
Depth2 Flow 956599
   No Flow  529 99
 as.data.frame.table(numbers) 
Var1Var2   Var3 Freq
1 Depth1FlowMussels 1134
2 Depth2FlowMussels  956
3 Depth1 No FlowMussels  328
4 Depth2 No FlowMussels  529
5 Depth1Flow No Mussels  435
6 Depth2Flow No Mussels  599
7 Depth1 No Flow No Mussels   27
8 Depth2 No Flow No Mussels   99
 frame - as.data.frame.table(numbers) 
 names(frame) - c(wd, wv, MP, Count) 
 frame 
  wd  wv MP Count
1 Depth1FlowMussels  1134
2 Depth2FlowMussels   956
3 Depth1 No FlowMussels   328
4 Depth2 No FlowMussels   529
5 Depth1Flow No Mussels   435
6 Depth2Flow No Mussels   599
7 Depth1 No Flow No Mussels27
8 Depth2 No Flow No Mussels99
 attach(frame) 
 model1 - glm(Count~MP+wd+wv,poisson) 
 summary(model1)

Call:
glm(formula = Count ~ MP + wd + wv, family = poisson)

Deviance Residuals: 
   1 2 3 4 5 6 7
8  
  2.5545   -7.0682   -0.13437.48891.05555.7533  -11.0107  
-4.2551  

Coefficients:
 Estimate Std. Error z value Pr(|z|)
(Intercept)   6.956680.02631 264.414   2e-16 ***
MPNo Mussels -0.932370.03466 -26.900   2e-16 ***
wdDepth2  0.126290.03127   4.039 5.37e-05 ***
wvNo Flow-1.156260.03657 -31.618   2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

(Dispersion parameter for poisson family taken to be 1)

Null deviance: 2279.76  on 7  degrees of freedom
Residual deviance:  286.14  on 4  degrees of freedom
AIC: 355.18

Number of Fisher Scoring iterations: 4


-- 
View this message in context: 
http://r.789695.n4.nabble.com/Three-dimensional-contingency-table-tp2398915p2399062.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Three-dimensional contingency table

2010-08-29 Thread David Winsemius


On Aug 28, 2010, at 10:58 PM, Randklev, Charles 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)


I don't get that error, so maybe you have more than one MP variable  
after attaching frame. Have you used ls() recently. If there is an  
extra MP you should see it there but it shouldn't show up if it is  
only attached. The attach function is a common cause of perplexing  
errors.


--
David.

__
R-help@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.