[R-sig-eco] Pred function with categorical factors

Chris Mcowen chrismcowen at gmail.com
Fri Aug 20 19:12:44 CEST 2010


Dear list, 

I am relatively new to R and GLM"S so please bear with me!


I am trying to plot a graph of my binary response (threat) on the Y axis and the variable SEA on the X-

I have used the following code but the graph looks odd ( https://files.me.com/chrismcowen/xz47o4) i presume it is because i have categorical factors? 

The SEA variable is categorical 1 - 4  

> mydata <- data.frame(SEA)
Pred <- predict(model1, newdata = mydata, type = "response"),
> plot(x = traits$SEA, y = traits$threat), 
> lines(mydata$SEA, Pred)

I also have another question - how do i predict a response with only the factors? I presume i calculate the log odds to get a probability for each factor(5) but i am not sure where to go from here?

model1 <- glm(THREAT~HAB*FR+BS+SEA+PD+WO)

coef(model1)
                (Intercept)                HABLithophyte 
                -0.11880089                   0.10498055 
            HABSemi-aquatic               HABTerrestrial 
                 0.36712439                   0.17641700 
               FRNon_fleshy          BSUnisexual_flowers 
                 0.35551197                  -0.00706299 
          BSUnisexual_plant               SEAHapaxanthic 
                 0.06857112                  -0.53281439 
               SEAPerrenial               SEAPleonanthic 
                 0.18798090                  -0.08547676 
                   PDBiotic                      WOWoody 
                 0.29155388                   0.12533079 
 HABLithophyte:FRNon_fleshy HABSemi-aquatic:FRNon_fleshy 
                 0.27595822                  -0.31031510 
HABTerrestrial:FRNon_fleshy 
                -0.31065039 



'data.frame':	1115 obs. of  20 variables:
$ order     : Factor w/ 9 levels "Alismatales",..: 7 3 3 8 8 8 8 8 8 8 ...
$ fam       : Factor w/ 42 levels "Agavaceae","Alliaceae",..: 40 34 34 36 11 11 11 11 11 36 ...
$ genus     : Factor w/ 449 levels "Acanthochlamys",..: 1 2 2 3 4 4 4 4 4 5 ...
$ species   : Factor w/ 1065 levels "abdulrahmanii",..: 123 429 851 1065 156 243 485 735 761 107 ...
$ Tip       : Factor w/ 1115 levels "Acanthochlamys_bracteata",..: 1 2 3 4 5 6 7 8 9 10 ...
$ HAB       : Factor w/ 4 levels "Epiphyte","Lithophyte",..: 4 1 1 4 1 1 1 1 1 4 ...
$ STO       : Factor w/ 2 levels "No_Storage_organ",..: 2 2 1 2 1 1 1 1 1 2 ...
$ BS        : Factor w/ 3 levels "Bisexual_flower",..: 1 1 1 3 1 1 1 1 1 1 ...
$ PD        : Factor w/ 2 levels "Abiotic","Biotic": 2 2 2 1 2 2 2 2 2 1 ...
$ FR        : Factor w/ 2 levels "Fleshy","Non_fleshy": 1 2 2 2 1 1 1 1 1 2 ...
$ END       : Factor w/ 2 levels "Endosperm","No_endosperm": 1 2 2 1 1 1 1 1 1 1 ...
$ WO        : Factor w/ 2 levels "Non_woody","Woody": 1 1 1 1 1 1 1 1 1 1 ...
$ RG        : Factor w/ 2 levels "One","Two+": 1 1 1 2 1 1 1 1 1 2 ...
$ SEA       : Factor w/ 4 levels "Annual","Hapaxanthic",..: 3 3 3 3 3 3 3 3 3 1 ...
$ SE        : Factor w/ 3 levels "Few","Numerous",..: 2 2 2 3 2 2 2 2 2 3 ...
$ FS        : Factor w/ 2 levels "Actinomorphic",..: 1 2 2 1 1 1 1 1 1 2 ...
$ IUCN      : Factor w/ 6 levels "CR","EN","LC",..: 4 5 6 3 5 1 5 6 4 3 ...
$ EXTINCTION: int  6 2 3 1 2 5 2 3 6 1 ...
$ THREAT    : int  1 0 1 0 0 1 0 1 1 0 ...
$ THREATtf  : logi  TRUE FALSE TRUE FALSE FALSE TRUE ...



More information about the R-sig-ecology mailing list