## ------------------------------------------------------------------------ # Generate 50 values drawn randomly from two different distributions: x is from a normal distribution and y from a uniform. # Thus, we *know* they should be different x <- rnorm(50) y <- runif(30) # Do x and y come from the same distribution? ks.test(x, y) ## ------------------------------------------------------------------------ BirdData <- data.frame( Tarsus = c(22.3, 19.7, 20.8, 20.3, 20.8, 21.5, 20.6, 21.5), Head = c(31.2, 30.4, 30.6, 30.3, 30.3, 30.8, 32.5, 31.6), Weight = c(9.5, 13.8, 14.8, 15.2, 15.5, 15.6, 15.6, 15.7), Wingcrd = c(59, 55, 53.5, 55, 52.5, 57.5, 53, 55), Species = c('A', 'A', 'A', 'A', 'A', 'B', 'B', 'B') ) ## ---- birdplots, fig.cap = "**Fig.** The relationships between measurements of sparrows"---- par(mfrow = c(2, 2)) plot(BirdData$Tarsus ~ BirdData$Wingcrd) plot(BirdData$Tarsus ~ BirdData$Head) plot(BirdData$Tarsus ~ BirdData$Weight) plot(BirdData$Head ~ BirdData$Wingcrd) ## ------------------------------------------------------------------------ cor(x = BirdData$Tarsus, y = BirdData$Wingcrd, method = 'pearson') ## ------------------------------------------------------------------------ cor.test(x = BirdData$Tarsus, y = BirdData$Wingcrd, method = 'pearson') ## ------------------------------------------------------------------------ cor.test(formula = ~ BirdData$Tarsus + BirdData$Wingcrd) ## ---- fig.cap = "**Fig.** Sparrow Wingcrd as a function of Tarsus length"---- plot(BirdData$Tarsus ~ BirdData$Wingcrd) ## ------------------------------------------------------------------------ m <- lm(BirdData$Tarsus ~ BirdData$Wingcrd) # or m <- lm(Tarsus ~ Wingcrd, data = BirdData) ## ------------------------------------------------------------------------ summary(m) ## ------------------------------------------------------------------------ coef(m) ## ------------------------------------------------------------------------ resid(m) ## ---- fig.cap = "**Fig.** Sparrow Wingcrd as a function of Tarsus length, with fitted line"---- plot(BirdData$Tarsus ~ BirdData$Wingcrd) abline(lm(BirdData$Tarsus ~ BirdData$Wingcrd)) # or m <- lm(BirdData$Tarsus ~ BirdData$Wingcrd) abline(m)