For your homework, we will use a sample plant diversity dataset to assess diversity called:

ENVS286_plant_abundance_SP17.csv

This dataset is measuring plant abundance for twelve grassland plots in Kansas. There are three habitat types (A, B, and C). You should have all the tools at your disposal from this lab (and previous labs) to answer the questions.

Q1: Why can’t you just feed the plant abundance data set into the vegan package functions directly?

You can’t just feed the plant abundance data set into the vegan package directly because there is missing data and the habitat row contains character strings.

Q2: Present the entire code that you would use to create a data frame with the three diversity indices for the plant abundance data.

plant <- read.csv("C:\\Users\\Gabriela Krochmal\\Downloads\\ENVS286_plant_abundance_SP17 (1).csv")
summary(plant)
##     Habitat  Achillea_millefolium Allium_textile Amelanchier_alnifolia
##  A1     :1   Min.   :10.00        Min.   :10     Min.   :10           
##  A2     :1   1st Qu.:30.00        1st Qu.:10     1st Qu.:10           
##  A3     :1   Median :35.00        Median :10     Median :10           
##  A4     :1   Mean   :33.33        Mean   :12     Mean   :10           
##  B1     :1   3rd Qu.:40.00        3rd Qu.:10     3rd Qu.:10           
##  B2     :1   Max.   :50.00        Max.   :20     Max.   :10           
##  (Other):6   NA's   :6            NA's   :7      NA's   :9            
##  Androsace_occidentalis Anemone_patens  Antennaria_neglecta
##  Min.   :10             Min.   :10.00   Min.   :20         
##  1st Qu.:10             1st Qu.:15.00   1st Qu.:20         
##  Median :20             Median :20.00   Median :20         
##  Mean   :30             Mean   :16.67   Mean   :20         
##  3rd Qu.:40             3rd Qu.:20.00   3rd Qu.:20         
##  Max.   :70             Max.   :20.00   Max.   :20         
##  NA's   :7              NA's   :9       NA's   :11         
##  Antennaria_parvifolia Arnica_fulgens Artemisia_cana Artemisia_frigida
##  Min.   :10.0          Min.   :30     Min.   :10.0   Min.   :20.00    
##  1st Qu.:12.5          1st Qu.:30     1st Qu.:10.0   1st Qu.:30.00    
##  Median :15.0          Median :30     Median :10.0   Median :50.00    
##  Mean   :15.0          Mean   :30     Mean   :12.5   Mean   :42.86    
##  3rd Qu.:17.5          3rd Qu.:30     3rd Qu.:12.5   3rd Qu.:55.00    
##  Max.   :20.0          Max.   :30     Max.   :20.0   Max.   :60.00    
##  NA's   :10            NA's   :11     NA's   :8      NA's   :5        
##  Artemisia_ludoviciana Aster_ericoides Aster_falcatus  Aster_laevis  
##  Min.   :20.0          Min.   :10      Min.   :20     Min.   :20.00  
##  1st Qu.:27.5          1st Qu.:10      1st Qu.:20     1st Qu.:45.00  
##  Median :40.0          Median :10      Median :20     Median :70.00  
##  Mean   :42.5          Mean   :10      Mean   :22     Mean   :53.33  
##  3rd Qu.:55.0          3rd Qu.:10      3rd Qu.:20     3rd Qu.:70.00  
##  Max.   :70.0          Max.   :10      Max.   :30     Max.   :70.00  
##  NA's   :8             NA's   :9       NA's   :7      NA's   :9      
##  Astragalus_aboriginum Astragalus_bisulcatus Astragalus_dasyglottis
##  Min.   :20            Min.   :10            Min.   :20.0          
##  1st Qu.:20            1st Qu.:10            1st Qu.:22.5          
##  Median :20            Median :10            Median :25.0          
##  Mean   :20            Mean   :10            Mean   :25.0          
##  3rd Qu.:20            3rd Qu.:10            3rd Qu.:27.5          
##  Max.   :20            Max.   :10            Max.   :30.0          
##  NA's   :11            NA's   :11            NA's   :10            
##  Bouteloua_gracilis Bromus_inermis Campanula_rotundifolia Carex_filifolia 
##  Min.   : 10.0      Min.   :10     Min.   :10.00          Min.   : 30.00  
##  1st Qu.: 67.5      1st Qu.:10     1st Qu.:10.00          1st Qu.: 65.00  
##  Median : 70.0      Median :10     Median :10.00          Median : 85.00  
##  Mean   : 70.0      Mean   :10     Mean   :16.67          Mean   : 76.67  
##  3rd Qu.: 90.0      3rd Qu.:10     3rd Qu.:20.00          3rd Qu.: 97.50  
##  Max.   :100.0      Max.   :10     Max.   :30.00          Max.   :100.00  
##  NA's   :4          NA's   :11     NA's   :9              NA's   :6       
##  Carex_obtusata   Cerastium_arvense Chenopodium_album Comandra_umbellata
##  Min.   : 50.00   Min.   :10        Min.   :20.0      Min.   :10        
##  1st Qu.: 70.00   1st Qu.:15        1st Qu.:42.5      1st Qu.:40        
##  Median : 85.00   Median :20        Median :55.0      Median :60        
##  Mean   : 81.67   Mean   :20        Mean   :47.5      Mean   :52        
##  3rd Qu.:100.00   3rd Qu.:25        3rd Qu.:60.0      3rd Qu.:70        
##  Max.   :100.00   Max.   :30        Max.   :60.0      Max.   :80        
##  NA's   :6        NA's   :9         NA's   :8         NA's   :7         
##  Descurainia_sophia Draba_nemorosa Elaeagnus_commutata Elymus_lanceolatus
##  Min.   :10         Min.   :10     Min.   :20          Min.   :10.00     
##  1st Qu.:10         1st Qu.:15     1st Qu.:20          1st Qu.:10.00     
##  Median :10         Median :20     Median :20          Median :30.00     
##  Mean   :10         Mean   :20     Mean   :20          Mean   :34.55     
##  3rd Qu.:10         3rd Qu.:25     3rd Qu.:20          3rd Qu.:50.00     
##  Max.   :10         Max.   :30     Max.   :20          Max.   :90.00     
##  NA's   :11         NA's   :9      NA's   :11          NA's   :1         
##  Elytrigia_repens Erigeron_glabellus Erigeron_pumilus
##  Min.   :20.0     Min.   :30         Min.   :20      
##  1st Qu.:27.5     1st Qu.:30         1st Qu.:20      
##  Median :35.0     Median :30         Median :20      
##  Mean   :35.0     Mean   :30         Mean   :20      
##  3rd Qu.:42.5     3rd Qu.:30         3rd Qu.:20      
##  Max.   :50.0     Max.   :30         Max.   :20      
##  NA's   :10       NA's   :11         NA's   :11      
##  Erysimum_inconspicuum Eurotia_lanata Festuca_hallii   Galium_boreale
##  Min.   :20            Min.   :10     Min.   : 30.00   Min.   : 30   
##  1st Qu.:20            1st Qu.:15     1st Qu.: 40.00   1st Qu.: 30   
##  Median :20            Median :20     Median : 75.00   Median : 40   
##  Mean   :20            Mean   :20     Mean   : 68.33   Mean   : 50   
##  3rd Qu.:20            3rd Qu.:25     3rd Qu.: 95.00   3rd Qu.: 50   
##  Max.   :20            Max.   :30     Max.   :100.00   Max.   :100   
##  NA's   :11            NA's   :9      NA's   :6        NA's   :7     
##  Gutierrezia_sarothrae Haplopappus_spinulosus Heterotheca_villosa
##  Min.   :10            Min.   :10             Min.   :10         
##  1st Qu.:10            1st Qu.:10             1st Qu.:10         
##  Median :10            Median :10             Median :10         
##  Mean   :10            Mean   :10             Mean   :10         
##  3rd Qu.:10            3rd Qu.:10             3rd Qu.:10         
##  Max.   :10            Max.   :10             Max.   :10         
##  NA's   :11            NA's   :11             NA's   :11         
##  Heuchera_richardsonii Hymenoxys_richardsonii Koeleria_macrantha
##  Min.   :10            Min.   :10             Min.   :10.00     
##  1st Qu.:10            1st Qu.:10             1st Qu.:30.00     
##  Median :10            Median :10             Median :40.00     
##  Mean   :10            Mean   :10             Mean   :53.33     
##  3rd Qu.:10            3rd Qu.:10             3rd Qu.:80.00     
##  Max.   :10            Max.   :10             Max.   :90.00     
##  NA's   :11            NA's   :11             NA's   :3         
##  Lactuca_pulchella Lathyrus_venosus Lepidium_densiflorum
##  Min.   :10.0      Min.   :10       Min.   :10          
##  1st Qu.:17.5      1st Qu.:10       1st Qu.:10          
##  Median :25.0      Median :10       Median :10          
##  Mean   :32.5      Mean   :10       Mean   :10          
##  3rd Qu.:40.0      3rd Qu.:10       3rd Qu.:10          
##  Max.   :70.0      Max.   :10       Max.   :10          
##  NA's   :8         NA's   :11       NA's   :11          
##  Musineon_divaricatum Oxytropis_sericea Penstemon_confertus
##  Min.   :20           Min.   :10        Min.   :10         
##  1st Qu.:20           1st Qu.:15        1st Qu.:10         
##  Median :20           Median :20        Median :10         
##  Mean   :20           Mean   :20        Mean   :10         
##  3rd Qu.:20           3rd Qu.:25        3rd Qu.:10         
##  Max.   :20           Max.   :30        Max.   :10         
##  NA's   :10           NA's   :10        NA's   :11         
##  Penstemon_nitidus Penstemon_procerus Petalostemon_purpureum
##  Min.   :10        Min.   :10         Min.   :40            
##  1st Qu.:10        1st Qu.:10         1st Qu.:40            
##  Median :10        Median :10         Median :40            
##  Mean   :10        Mean   :10         Mean   :40            
##  3rd Qu.:10        3rd Qu.:10         3rd Qu.:40            
##  Max.   :10        Max.   :10         Max.   :40            
##  NA's   :11        NA's   :11         NA's   :11            
##   Phlox_hoodii   Plantago_patagonica  Poa_cusickii   Poa_pratensis
##  Min.   :30.00   Min.   :20.00       Min.   :10.00   Min.   : 10  
##  1st Qu.:40.00   1st Qu.:25.00       1st Qu.:15.00   1st Qu.: 60  
##  Median :50.00   Median :30.00       Median :20.00   Median : 60  
##  Mean   :46.67   Mean   :33.33       Mean   :36.67   Mean   : 65  
##  3rd Qu.:55.00   3rd Qu.:40.00       3rd Qu.:50.00   3rd Qu.: 90  
##  Max.   :60.00   Max.   :50.00       Max.   :80.00   Max.   :100  
##  NA's   :9       NA's   :9           NA's   :9       NA's   :6    
##  Poa_sandbergii Potentilla_arguta Rosa_arkansana  Solidago_missouriensis
##  Min.   : 30    Min.   :10        Min.   :20.00   Min.   :10            
##  1st Qu.: 50    1st Qu.:10        1st Qu.:22.50   1st Qu.:15            
##  Median : 70    Median :10        Median :35.00   Median :20            
##  Mean   : 66    Mean   :10        Mean   :41.67   Mean   :30            
##  3rd Qu.: 80    3rd Qu.:10        3rd Qu.:55.00   3rd Qu.:40            
##  Max.   :100    Max.   :10        Max.   :80.00   Max.   :60            
##  NA's   :7      NA's   :11        NA's   :6       NA's   :9             
##  Solidago_rigida Sphaeralcea_coccinea  Stipa_comata    Stipa_spartea  
##  Min.   :10      Min.   :20           Min.   : 10.00   Min.   : 20.0  
##  1st Qu.:10      1st Qu.:20           1st Qu.: 42.50   1st Qu.: 42.5  
##  Median :10      Median :30           Median : 85.00   Median : 65.0  
##  Mean   :10      Mean   :32           Mean   : 68.33   Mean   : 62.5  
##  3rd Qu.:10      3rd Qu.:40           3rd Qu.: 97.50   3rd Qu.: 85.0  
##  Max.   :10      Max.   :50           Max.   :100.00   Max.   :100.0  
##  NA's   :11      NA's   :7            NA's   :6        NA's   :8      
##  Stipa_viridula Symphoricarpos_occidentalis Taraxacum_officinale
##  Min.   :10.0   Min.   :10.0                Min.   :10          
##  1st Qu.:10.0   1st Qu.:17.5                1st Qu.:15          
##  Median :15.0   Median :20.0                Median :20          
##  Mean   :27.5   Mean   :17.5                Mean   :20          
##  3rd Qu.:32.5   3rd Qu.:20.0                3rd Qu.:25          
##  Max.   :70.0   Max.   :20.0                Max.   :30          
##  NA's   :8      NA's   :8                   NA's   :9           
##  Thermopsis_rhombifolia Tragopogon_dubius Vicia_americana  Viola_adunca 
##  Min.   :10             Min.   :10        Min.   :20      Min.   :10.0  
##  1st Qu.:10             1st Qu.:10        1st Qu.:20      1st Qu.:12.5  
##  Median :30             Median :10        Median :20      Median :15.0  
##  Mean   :30             Mean   :10        Mean   :30      Mean   :15.0  
##  3rd Qu.:45             3rd Qu.:10        3rd Qu.:35      3rd Qu.:17.5  
##  Max.   :60             Max.   :10        Max.   :50      Max.   :20.0  
##  NA's   :5              NA's   :10        NA's   :9       NA's   :10    
##  Zigadenus_venenosus
##  Min.   :50         
##  1st Qu.:50         
##  Median :50         
##  Mean   :50         
##  3rd Qu.:50         
##  Max.   :50         
##  NA's   :11
library(vegan)
## Loading required package: permute
## Loading required package: lattice
## This is vegan 2.4-3
plant[is.na(plant)] <- 0 
rownames(plant) <- plant$Habitat
plant$Habitat <- NULL
plantspecies <- specnumber(plant)
Hplant <- diversity(plant, index="shannon")
Dplant <- diversity(plant, index="invsimpson")
diversityResult <- data.frame(plantspecies, Hplant, Dplant)
diversityResult$Habitat <- rownames(diversityResult)
plant$HabitatFactor <- c("A","A","A","A","B","B","B","B",
                         "C","C","C","C")

Important Note: Once you get the final dataframe for your diversity indices above, you must as a column to create an (A, B, C) factor to run an ANOVA. To do this…

yourPlantDataframeName$HabitatFactor <- c(A,A,A,A,B,B,B,B,C,C,C,C)

Q3: Choose one of the diversity indices for the plant abundance dataset. Run an ANOVA to analyze the results (check your assumptions). Supply the following:

A) Plot of your data

diversityResult$Habitat <- rownames(diversityResult)
diversityResult$HabitatFactor <- as.factor(c("A","A","A","A","B","B","B","B",
                         "C","C","C","C"))
plot(plantspecies ~ HabitatFactor, data = diversityResult)

#boxplot of my data

B) evidence of residual normality and homoscedasticity

The data is mostly normal based on what I saw from the qqplots and how close the data was to 1:1 line, and it does have homogenity of variance because the data in the Residuals vs Fitted data is good and almost has the shape of the rectangle

qqnorm(Dplant)
qqline(Dplant)   #qq plot of my data showing that it is close to the 1:1 line, so the data looks normal. 

Dplant.aov <- aov(Dplant ~ HabitatFactor, data=plant)
plot(Dplant.aov) #ANOVA plot showing the homoscedascity of my data, and my data looks mostly normal. 

## hat values (leverages) are all = 0.25
##  and there are no factor predictors; no plot no. 5

C) ANOVA output

My pvalue was 0.274 so my data is not significantly different, and I accept my null hypothesis.

summary(Dplant.aov) #table of my data afer ANOVA
##               Df Sum Sq Mean Sq F value Pr(>F)
## HabitatFactor  2  61.13   30.56   1.498  0.274
## Residuals      9 183.62   20.40

D) Tukey HSD results (if applicable)

I did not need to perform a Tukey test because I accepted null hypothesis that the means were equal, so no need for comparison.

E) Reported Results Paragraph

The Dplant habitats were not significantly different because the pvalue was 0.274 which is greater than 0.05. This meant that I accepted my null hypothesis that all means were equal. I did not need to run a Tukey test.

F) graph created with the plotting gizmo. Be sure to include an informative figure captions for the graphs.

GIZMO GIVEN BELOW. Remember: You need to adjust the parameters.
Figure 1: Habitat diversity comparision.

Figure 1: Habitat diversity comparision.

Please turn–in your homework via Sakai by saving and submitting an R Markdown PDF or HTML file from R Pubs!