Renaming GLM
R's generalized linear regression function, glm(), suffers the same usability problems as lm(): its name is an acronym, and its formula and data arguments are in the wrong order.
To solve this exercise, you need to know two things about generalized linear regression:
glm()formulas are specified likelm()formulas: response is on the left, and explanatory variables are added on the right.- To model count data, set
glm()'sfamilyargument topoisson, making it a Poisson regression.
Here you'll use data on the number of yearly visits to Snake River at Jackson Hole, Wyoming, snake_river_visits.
Diese Übung ist Teil des Kurses
Introduction to Writing Functions in R
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Run a generalized linear regression
___(
# Model no. of visits vs. gender, income, travel
___ ~ ___ + ___ + ___,
# Use the snake_river_visits dataset
data = ___,
# Make it a Poisson regression
family = ___
)