1
$\begingroup$

i´m new with R and i have a question to do. i´m doing a study on seed germination and i have trouble doing a priori contrasts for a GLM analysis. My response variable is proportion of seeds germinated and my explanatory variables are treatment with 3 levels (consumida, fruto, S/P) and species with 4 levels (chaqueña,guaviyu,mora,picazu).

My model is this: Modelo2 <- glm (Proporción ~ tratamiento*sp,family = quasibinomial,weights = semillas.por.maceta,data = Datos).

> summary(Modelo2)
Call:
glm(formula = Proporción ~ tratamiento * sp, family = quasibinomial, 
    data = Datos, weights = semillas.por.maceta)
Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-3.1963  -1.2417  -0.1850   0.7471   6.4915  
Coefficients:
                           Estimate Std. Error t value Pr(>|t|)    
(Intercept)                 -1.9924     0.2921  -6.822 2.36e-11 ***
tratamientoFruto            -1.9105     0.3565  -5.359 1.23e-07 ***
tratamientoS/P              -0.2501     0.4349  -0.575 0.565516    
spGuaviyu                    1.5692     0.3541   4.432 1.13e-05 ***
spMora                       0.5554     0.3381   1.642 0.101071    
spPicazú                     2.5678     0.3527   7.280 1.15e-12 ***
tratamientoFruto:spGuaviyu   1.5276     0.4559   3.350 0.000862 ***
tratamientoS/P:spGuaviyu    -0.3727     0.5254  -0.709 0.478372    
tratamientoFruto:spMora      0.9196     0.4697   1.958 0.050745 .  
tratamientoS/P:spMora        1.1204     0.4875   2.298 0.021911 *  
tratamientoFruto:spPicazú  -17.2014   609.9876  -0.028 0.977513    
tratamientoS/P:spPicazú     -0.6810     0.5152  -1.322 0.186726    
---Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for quasibinomial family taken to be 2.252043)
    Null deviance: 2671.7  on 566  degrees of freedom
Residual deviance: 1311.0  on 555  degrees of freedom
AIC: NA
Number of Fisher Scoring iterations: 16

My problem is that i dont know how to do a priori constrasts. I want to contrast the 3 treatments (consumida vs fruto, consumida vs S/P, and fruto vs S/P) for each one of the 4 species (i need to do 12 contrasts).

i tried to do a new model with the interaction between species and treatment, and a matrix for planned contrast like is detailed after, but it didn´t work. 3 coefficients were not defined and 1 contrast (the last one) didn´t appear on summary.

Datos$interaccion<- with(Datos, interaction(tratamiento,sp))

modelo3<-glm(Proporción ~ interaccion,family = quasibinomial,weights = semillas.por.maceta,data = Datos)

> summary(modelo3)

Call:
glm(formula = Proporción ~ interaccion, family = quasibinomial, 
    data = Datos, weights = semillas.por.maceta)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-3.1963  -1.2417  -0.1850   0.7471   6.4915  

Coefficients:
                             Estimate Std. Error t value Pr(>|t|)    
(Intercept)                   -1.9924     0.2921  -6.822 2.36e-11 ***
interaccionFruto.Chaqueña     -1.9105     0.3565  -5.359 1.23e-07 ***
interaccionS/P.Chaqueña       -0.2501     0.4349  -0.575 0.565516    
interaccionconsumida.Guaviyu   1.5692     0.3541   4.432 1.13e-05 ***
interaccionFruto.Guaviyu       1.1863     0.3550   3.342 0.000888 ***
interaccionS/P.Guaviyu         0.9465     0.3635   2.604 0.009466 ** 
interaccionconsumida.Mora      0.5554     0.3381   1.642 0.101071    
interaccionFruto.Mora         -0.4355     0.3870  -1.125 0.260971    
interaccionS/P.Mora            1.4257     0.3237   4.404 1.28e-05 ***
interaccionconsumida.Picazú    2.5678     0.3527   7.280 1.15e-12 ***
interaccionFruto.Picazú      -16.5441   609.9876  -0.027 0.978372    
interaccionS/P.Picazú          1.6367     0.3500   4.677 3.67e-06 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for quasibinomial family taken to be 2.252043)

    Null deviance: 2671.7  on 566  degrees of freedom
Residual deviance: 1311.0  on 555  degrees of freedom
AIC: NA

Number of Fisher Scoring iterations: 16

c1<- c(1,-1,0,0,0,0,0,0,0,0,0,0)

c2<- c(1,0,-1,0,0,0,0,0,0,0,0,0)

c3<- c(0,1,-1,0,0,0,0,0,0,0,0,0)

c4<- c(0,0,0,1,-1,0,0,0,0,0,0,0)

c5<- c(0,0,0,1,0,-1,0,0,0,0,0,0)

c6<- c(0,0,0,0,1,-1,0,0,0,0,0,0)

c7<- c(0,0,0,0,0,0,1,-1,0,0,0,0)

c8<- c(0,0,0,0,0,0,1,0,-1,0,0,0)

c9<- c(0,0,0,0,0,0,0,1,-1,0,0,0)

c10<- c(0,0,0,0,0,0,0,0,0,1,-1,0)

c11<- c(0,0,0,0,0,0,0,0,0,1,0,-1)

c12<- c(0,0,0,0,0,0,0,0,0,0,1,-1)

contrasts(Datos$interaccion)<-cbind(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12)

modelo3b<-glm(Proporción ~ interaccion,family = quasibinomial,weights = semillas.por.maceta,data = Datos)

summary(modelo3b)

> summary(modelo3b)
Call:
glm(formula = Proporción ~ interaccion, family = quasibinomial, 
    data = Datos, weights = semillas.por.maceta)
Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-3.2284  -1.3449  -0.2286   0.8360   6.9048  
Coefficients: (3 not defined because of singularities)
               Estimate Std. Error t value Pr(>|t|)    
(Intercept)    -1.66256    0.08245 -20.164  < 2e-16 ***
interaccionc1   1.60228    0.15779  10.154  < 2e-16 ***
interaccionc2  -0.74367    0.18759  -3.964 8.31e-05 ***
interaccionc3        NA         NA      NA       NA    
interaccionc4  -0.00522    0.24453  -0.021   0.9830    
interaccionc5   0.47006    0.26586   1.768   0.0776 .  
interaccionc6        NA         NA      NA       NA    
interaccionc7   1.09714    0.21891   5.012 7.25e-07 ***
interaccionc8  -1.00737    0.15757  -6.393 3.44e-10 ***
interaccionc9        NA         NA      NA       NA    
interaccionc10  3.58896    0.34767  10.323  < 2e-16 ***
interaccionc11 -1.32834    0.23259  -5.711 1.83e-08 ***
---Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for quasibinomial family taken to be 2.985274)
    Null deviance: 2671.7  on 566  degrees of freedom
Residual deviance: 1563.5  on 558  degrees of freedom
AIC: NA
Number of Fisher Scoring iterations: 5

Can somebody help me please? i ll be thankful

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.