R Tutorial : Basic lm() functions with glm()

DataCamp · Beginner ·🛠️ AI Tools & Apps ·6y ago

Key Takeaways

The video demonstrates the application of lm() functions to Generalized Linear Models (GLMs) in R, using functions like print, summary, tidy, coef, confint, and predict to understand and use GLM outputs.

Full Transcript

welcome back during the previous exercises you learned about Poisson regressions now you will learn how L M functions can be applied to GL ends these functions help us understand and use GLM outputs besar has many functions for interacting with linear models and by extension GL ends in fact both lms and GLM's form a back one of our and its predecessor s the original authors of these languages often use LM s these functions allow us to easily access some parts of models thus rather than needing to manually interrogate an extract model outputs are gives helpful shortcuts these shortcuts allow us to see model outputs with functions like print and also makes statistical inferences with functions like summary when we were running at G L M model outputs automatically appear just like an LM alternatively we can explicitly print model outputs using the print function this output tells us several useful things including what model was fit or called the estimated coefficients the degrees of freedom which can be thought of as how many extra observations we have the null deviance and residual deviance which is the GLM version of residuals and the AIC score for the model in contrast to print summary provides more detail the first part of a summary output is the same as print and I did not include it here to save space the next portion of the GLM summary includes the Assembly of the deviance residuals which can be helpful for understanding a model fit next summary displays coefficients as well as your standard errors z-scores and p-values these can tell us if coefficients explain more variability than will be expected by chance alone next summary tells us about dispersion although not covered in this course some data can be over dispersed and neither have more variants or zeros than the model suggests these models require special over dispersion parameters next the model provides us similar deviance and degree of freedom information as the output last summary provides us with the Fischer scoring iterations which can be helpful if R has trouble fitting a model the tidy version also provides a standardized model output the tidy function in the broom package if we only want to look at the regression coefficients we can extract them using the couette function this provides us with the coefficient estimates for a model we might want to extract coefficients to either plot them or use them in future analysis similar to the coefficient function we can also estimate and display coefficient intervals using the confident function this function could take a while to run an R for larger models we can also change which intervals we estimate using the level option and only estimate the confidence interval for select parameters using the param option as a data scientist we often want to use models to predict future events like linear models the predict function can be used with g lms to use a fitted model with new data and make predictions if no new data file is specified then the predict function returns predictions based on the data used to fit the model if new data is specified the data from the prediction function is a vector that corresponds to the new data data frame you will get to apply these functions on GL and outputs that examine daily civilian non firefighter injuries this data is from Louisville Kentucky the data needs to be modeled using a Poisson distribution because it is count data with many zeros now let's look at the fire data and learn how to explore Geo

Original Description

Want to learn more? Take the full course at https://learn.datacamp.com/courses/generalized-linear-models-in-r at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work. --- Welcome back. During the previous exercises, you learned about Poisson regressions. Now, you will learn how lm() functions can be applied to glm()s. These functions help to understand and use GLM outputs. Base R has many functions for interacting with linear models, and by extensions GLMs. In fact, both LMs and GLMs form a backbone of R and its predecessor S. The original authors of these languages often used LMs. These functions allow us to easily access some parts of models. Thus, rather than needing to manually interrogate and extract model outputs, R gives helpful shortcuts. These shortcuts allows us to see the model outputs with function like print() and also make statistical inferences with function like summary(). When we run a GLM, model output automatically appears, just like a LM. Alternatively, we can explicitly print model output using the print function. This output tells us several useful things including what model was fit or "call"ed; the estimated coefficients; the degrees of freedom (which can be thought of as how many "extra" observations we have); the null deviance and residual deviance (which is the GLM version of residuals); and the AIC score for the model. In contrast to print(), summary() provides more details. The first part of a summary output is the same as print and I did not include it to save space. The next portion of the glm() summary() includes a summary of the deviance residuals, which can be helpful for understanding a model fit. Next, summary displays coefficients as well as their standard errors, z-scores, and p-values. These can tell us if coefficient explains more variability than would be expected by chance alone. Next, summary() tells us about dispersion. Although not covered in this cour
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from DataCamp · DataCamp · 0 of 60

← Previous Next →
1 SQL Server Tutorial: Date manipulation
SQL Server Tutorial: Date manipulation
DataCamp
2 R Tutorial: Intermediate Interactive Data Visualization with plotly in R
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
3 R Tutorial: Adding aesthetics to represent a variable
R Tutorial: Adding aesthetics to represent a variable
DataCamp
4 R Tutorial: Moving Beyond Simple Interactivity
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
5 Python Tutorial: Why use ML for marketing? Strategies and use cases
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
6 Python Tutorial: Preparation for modeling
Python Tutorial: Preparation for modeling
DataCamp
7 Python Tutorial: Machine Learning modeling steps
Python Tutorial: Machine Learning modeling steps
DataCamp
8 R Tutorial: The prior model
R Tutorial: The prior model
DataCamp
9 R Tutorial: Data & the likelihood
R Tutorial: Data & the likelihood
DataCamp
10 R Tutorial: The posterior model
R Tutorial: The posterior model
DataCamp
11 R Tutorial: An Introduction to plotly
R Tutorial: An Introduction to plotly
DataCamp
12 R Tutorial: Plotting a single variable
R Tutorial: Plotting a single variable
DataCamp
13 R Tutorial: Bivariate graphics
R Tutorial: Bivariate graphics
DataCamp
14 Python Tutorial: Customer Segmentation in Python
Python Tutorial: Customer Segmentation in Python
DataCamp
15 Python Tutorial: Time cohorts
Python Tutorial: Time cohorts
DataCamp
16 Python Tutorial: Calculate cohort metrics
Python Tutorial: Calculate cohort metrics
DataCamp
17 Python Tutorial: Cohort analysis visualization
Python Tutorial: Cohort analysis visualization
DataCamp
18 R Tutorial: Building Dashboards with flexdashboard
R Tutorial: Building Dashboards with flexdashboard
DataCamp
19 R Tutorial: Anatomy of a flexdashboard
R Tutorial: Anatomy of a flexdashboard
DataCamp
20 R Tutorial: Layout basics
R Tutorial: Layout basics
DataCamp
21 R Tutorial: Advanced layouts
R Tutorial: Advanced layouts
DataCamp
22 Python Tutorial: Time Series Analysis in Python
Python Tutorial: Time Series Analysis in Python
DataCamp
23 Python Tutorial: Correlation of Two Time Series
Python Tutorial: Correlation of Two Time Series
DataCamp
24 Python Tutorial: Simple Linear Regressions
Python Tutorial: Simple Linear Regressions
DataCamp
25 Python Tutorial: Autocorrelation
Python Tutorial: Autocorrelation
DataCamp
26 R Tutorial: The gapminder dataset
R Tutorial: The gapminder dataset
DataCamp
27 R Tutorial: The filter verb
R Tutorial: The filter verb
DataCamp
28 R Tutorial: The arrange verb
R Tutorial: The arrange verb
DataCamp
29 R Tutorial: The mutate verb
R Tutorial: The mutate verb
DataCamp
30 R Tutorial: What is cluster analysis?
R Tutorial: What is cluster analysis?
DataCamp
31 R Tutorial: Distance between two observations
R Tutorial: Distance between two observations
DataCamp
32 R Tutorial: The importance of scale
R Tutorial: The importance of scale
DataCamp
33 R Tutorial: Measuring distance for categorical data
R Tutorial: Measuring distance for categorical data
DataCamp
34 Python Tutorial: Plotting multiple graphs
Python Tutorial: Plotting multiple graphs
DataCamp
35 Python Tutorial: Customizing axes
Python Tutorial: Customizing axes
DataCamp
36 Python Tutorial: Legends, annotations, & styles
Python Tutorial: Legends, annotations, & styles
DataCamp
37 Python Tutorial: Introduction to iterators
Python Tutorial: Introduction to iterators
DataCamp
38 Python Tutorial: Playing with iterators
Python Tutorial: Playing with iterators
DataCamp
39 Python Tutorial: Using iterators to load large files into memory
Python Tutorial: Using iterators to load large files into memory
DataCamp
40 SQL Tutorial: Introduction to Relational Databases in SQL
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
41 SQL Tutorial: Tables: At the core of every database
SQL Tutorial: Tables: At the core of every database
DataCamp
42 SQL Tutorial: Update your database as the structure changes
SQL Tutorial: Update your database as the structure changes
DataCamp
43 Python Tutorial: Classification-Tree Learning
Python Tutorial: Classification-Tree Learning
DataCamp
44 Python Tutorial: Decision-Tree for Classification
Python Tutorial: Decision-Tree for Classification
DataCamp
45 Python Tutorial: Decision-Tree for Regression
Python Tutorial: Decision-Tree for Regression
DataCamp
46 Python Tutorial: Census Subject Tables
Python Tutorial: Census Subject Tables
DataCamp
47 Python Tutorial: Census Geography
Python Tutorial: Census Geography
DataCamp
48 Python Tutorial: Using the Census API
Python Tutorial: Using the Census API
DataCamp
49 R Tutorial: A/B Testing in R
R Tutorial: A/B Testing in R
DataCamp
50 R Tutorial: Baseline Conversion Rates
R Tutorial: Baseline Conversion Rates
DataCamp
51 R Tutorial: Designing an Experiment - Power Analysis
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
52 R Tutorial: Introduction to qualitative data
R Tutorial: Introduction to qualitative data
DataCamp
53 R Tutorial: Understanding your qualitative variables
R Tutorial: Understanding your qualitative variables
DataCamp
54 R Tutorial: Making Better Plots
R Tutorial: Making Better Plots
DataCamp
55 SQL Tutorial: OLTP and OLAP
SQL Tutorial: OLTP and OLAP
DataCamp
56 SQL Tutorial: Storing data
SQL Tutorial: Storing data
DataCamp
57 SQL Tutorial: Database design
SQL Tutorial: Database design
DataCamp
58 Python Tutorial: Introduction to spaCy
Python Tutorial: Introduction to spaCy
DataCamp
59 Python Tutorial: Statistical Models
Python Tutorial: Statistical Models
DataCamp
60 Python Tutorial: Rule-based Matching
Python Tutorial: Rule-based Matching
DataCamp

This video teaches how to apply lm() functions to Generalized Linear Models (GLMs) in R, and how to use various functions to understand and interpret GLM outputs. The video covers topics such as model evaluation, statistical inference, and data analysis.

Key Takeaways
  1. Load the necessary R packages
  2. Fit a GLM model to the data
  3. Use the print function to display model outputs
  4. Use the summary function to display detailed model outputs
  5. Use the tidy function to display standardized model outputs
  6. Use the coef function to extract regression coefficients
  7. Use the confint function to estimate coefficient intervals
  8. Use the predict function to make predictions with the fitted model
💡 The lm() functions can be applied to GLMs in R to understand and use GLM outputs, and various functions such as print, summary, tidy, coef, confint, and predict can be used to interpret and analyze the model outputs.

Related AI Lessons

Up next
Salesforce Flow New Features (Summer '26) | Open Record, URL & Show Toast Messages
AITECHONE
Watch →