xeris-s_lair

ch 11 problems

Nov 11th, 2025 (edited)
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.77 KB | Source Code | 0 0
  1. # Chapter 11 problems 5 & 6
  2.         ## ch 11 prob 5
  3. > data=read.csv("C:/Users/benny/Downloads/ch11_prob5_data.csv")
  4. > View(data) #this data looks stacked already
  5.     # in tutorial: 'values' = biomass & 'group' = species, 'dataset' = data
  6. > data$species=as.factor(data$species) #makes sure the factors are read as distinct factors
  7.   # for each group n=10, which is small, so we check ANOVA for Normality
  8. > shapiro.test(residuals(lm(biomass~species,data))) #IDK WHAT I DID DIFFERENT FROM LAST NIGHT BUT IT WORKS NOW. CODING IS SO    
  9.         # FRUSTRATING ##i checked, i swapped biomass and species
  10.   # W = 0.96669  pval = 0.2814, not (lessthan/equalto)0.05, therefore pop dist is Normal
  11. > bartlett.test(biomass~species,data)
  12.   #k-sq'd=0.72394  df=3  p-val=0.8676 (>0.05 therefore "insufficient evidence to suggest that the group variances differ", therefore    
  13.   # equal var. ANOVA is appropriate)
  14. > summary(aov(biomass~species,data)) #one-way ANOVA test w equal variances
  15.   # Pr(>F)= 0.00287
  16. > TukeyHSD(aov(biomass~species,data))
  17. ######################################
  18. ##  problem 6 - environmental lead  ##
  19. ######################################
  20. > data=read.csv("C:/Users/benny/Downloads/ch11_prob6_data.csv")
  21. > View(data)
  22.     # 'group' = year, 'values' = lead #
  23. > data$year=as.factor(data$year)
  24. > shapiro.test(residuals(lm(lead~year,data)))
  25.     # w=0.86602   p-value=1.197e-13 (super small)
  26. > library(psych)
  27. > describeBy(data$lead,data$year)
  28. > summary(aov(lead~year,data))
  29.     #p-val=0.0673
  30. > TukeyHSD(aov(lead~year,data))
  31.     ###^^^^^^^^^^^^^^^^^^^^###
  32.     ## prob 7 - cont. off 6 ##
  33. > boxplot(lead~year,data)
  34. > kruskal.test(lead~year,data)
  35. > install.packages("DescTools")
  36. > library(DescTools)
  37. > NemenyiTest(x=data$lead,g=data$year,dist = "tukey") #sample sizes (n) are equal, so we use Nemenyi test
Advertisement
Add Comment
Please, Sign In to add comment