Publications by StatsWithSarah
Week 3
This week we learned about poisson regression. With poisson regression, there are 4 assumptions. 1) The response variable is a count per unit of time 2) All observations are independent 3) E(X) = Var(X) 4) Log of the mean (lambda) is a linear function of x library(faraway) data(gala) attach(gala) This example uses data of the number of tortoise...
430 sym R (2369 sym/8 pcs) 1 img
Week 2
This week we went further in-depth on model selection and also different tests for model comparison We learned about two different methods for building a model: forward selection and backward selection. Forward selection is when you start with the grand mean model and then add in the most significant variable one at a time until there are no more...
3324 sym R (4251 sym/12 pcs)
Residuals
library(ggplot2) ## Warning: package 'ggplot2' was built under R version 3.6.3 data <- read.csv("http://www.cknudson.com/data/MacNaturalGas.csv") mod1 <- lm(therms ~ month, data) ggplot(data, aes(month, therms)) + geom_point() ## Warning: Removed 12 rows containing missing values (geom_point). data$monthsquared <- (data$month)^2 mod2 <- lm(th...
259 sym R (8229 sym/57 pcs) 21 img
Week 1
This week we covered linear regression and also conducting some residual analysis. The following code demonstrates how to create a linear model, and comparing two different models with ANOVA tests. In order to conduct an ANOVA test, you must be using nested models. From the example below, model1 is nested in model2. We could not do ANOVA between ...
1385 sym R (1513 sym/25 pcs) 7 img
Likelihood Homework
Question 2 #This function builds the log likelihood function for a poisson, which is found by multiplying independent poissons together, taking the log, and then taking the derivative loglike <- function(lambda, sumx = 100, n = 15) + {sumx*log(lambda) + -n*lambda} #This will test different values of lamba into the function to plot. I went up to...
311 sym R (5641 sym/20 pcs) 1 img
Logistic Regression Homework
This homework is for Sarah, Cheyanne, Lukas, and Cameron TITANIC library(stableGR) ## Loading required package: mcmcse ## mcmcse: Monte Carlo Standard Errors for MCMC ## Version 1.4-1 created on 2020-01-29. ## copyright (c) 2012, James M. Flegal, University of California, Riverside ## John Hughes, University of Colorado, D...
702 sym R (30649 sym/144 pcs) 2 img
Week 5
crabs <- read.csv("http://www.cknudson.com/data/crabs.csv") library(faraway) head(crabs) ## color spine width satell weight y ## 1 medium bad 28.3 8 3050 1 ## 2 dark bad 22.5 0 1550 0 ## 3 light good 26.0 9 2300 1 ## 4 dark bad 24.8 0 2100 0 ## 5 dark bad 26.0 4 2600 1 ## 6 medium...
141 sym R (6372 sym/31 pcs)
Poisson Regression Quiz
Emergency Health Services library(faraway) library(ggplot2) library(cats) data(esdcomp) summary(esdcomp) ## visits complaints residency gender revenue ## Min. : 879 Min. : 0.000 N:24 F:12 Min. :206.4 ## 1st Qu.:2036 1st Qu.: 1.000 Y:20 M:32 1st Qu.:235.9 ## Median :2384 Median : 2...
5455 sym R (9985 sym/60 pcs) 16 img
Poisson Regression Homework
SATELLITE CRABS crabby <- read.csv("http://www.cknudson.com/data/crabs.csv") summary(crabby) ## color spine width satell ## Length:173 Length:173 Min. :21.0 Min. : 0.000 ## Class :character Class :character 1st Qu.:24.9 1st Qu.: 0.000 ## Mode :character Mode ...
8581 sym R (15836 sym/73 pcs) 17 img
Week 4
This week we focused more on poisson regression and several criterias for model selection and adding/dropping variables. I’ll walk through a few. ## visits complaints residency gender revenue ## Min. : 879 Min. : 0.000 N:24 F:12 Min. :206.4 ## 1st Qu.:2036 1st Qu.: 1.000 Y:20 M:32 1st Qu....
987 sym R (1606 sym/13 pcs) 1 img