# Chapter 11 problems 5 & 6
## ch 11 prob 5
> data=read.csv("C:/Users/benny/Downloads/ch11_prob5_data.csv")
> View(data) #this data looks stacked already
# in tutorial: 'values' = biomass & 'group' = species, 'dataset' = data
> data$species=as.factor(data$species) #makes sure the factors are read as distinct factors
# for each group n=10, which is small, so we check ANOVA for Normality
> shapiro.test(residuals(lm(biomass~species,data))) #IDK WHAT I DID DIFFERENT FROM LAST NIGHT BUT IT WORKS NOW. CODING IS SO
# FRUSTRATING ##i checked, i swapped biomass and species
# W = 0.96669 pval = 0.2814, not (lessthan/equalto)0.05, therefore pop dist is Normal
> bartlett.test(biomass~species,data)
#k-sq'd=0.72394 df=3 p-val=0.8676 (>0.05 therefore "insufficient evidence to suggest that the group variances differ", therefore
# equal var. ANOVA is appropriate)
> summary(aov(biomass~species,data)) #one-way ANOVA test w equal variances
# Pr(>F)= 0.00287
> TukeyHSD(aov(biomass~species,data))
######################################
## problem 6 - environmental lead ##
######################################
> data=read.csv("C:/Users/benny/Downloads/ch11_prob6_data.csv")
> View(data)
# 'group' = year, 'values' = lead #
> data$year=as.factor(data$year)
> shapiro.test(residuals(lm(lead~year,data)))
# w=0.86602 p-value=1.197e-13 (super small)
> library(psych)
> describeBy(data$lead,data$year)
> summary(aov(lead~year,data))
#p-val=0.0673
> TukeyHSD(aov(lead~year,data))
###^^^^^^^^^^^^^^^^^^^^###
## prob 7 - cont. off 6 ##
> boxplot(lead~year,data)
> kruskal.test(lead~year,data)
> install.packages("DescTools")
> library(DescTools)
> NemenyiTest(x=data$lead,g=data$year,dist = "tukey") #sample sizes (n) are equal, so we use Nemenyi test