Statistics with R (1) – Linear regression

In this video, I show how to use R to fit a linear regression model using the lm() command. I also introduce how to plot the regression line and the overall arithmetic mean of the response variable, and I briefly explain the use of diagnostic plots to inspect the residuals. Basic features of the R interface (script window, console window) are introduced.

The R code used in this video is:

data(airquality)
names(airquality)

#[1] “Ozone” “Solar.R” “Wind” “Temp” “Month” “Day”

plot(Ozone~Solar.R,data=airquality)

#calculate mean ozone concentration (na´s removed)
mean.Ozone=mean(airquality$Ozone,na.rm=T)

abline(h=mean.Ozone)

#use lm to fit a regression line through these data:

model1=lm(Ozone~Solar.R,data=airquality)

model1

abline(model1,col=”red”)
plot(model1)

termplot(model1)
summary(model1)

Comments

Paul S says:

Thanks a ton, ur awesome

Oleksandr Sholin says:

Thank you very much, everything works pretty well, now I understand at least some stuff in R.

JWAN ALI says:

thank you

flamboyant person says:

Hello, please come back and make more vidoes on R we really need you Sir.

Prof Nandish Patel says:

Thank you Christoph! Excellent introduction to R. Simiplicity is most effective for learning. :)

Laura Lorenzo says:

This is great!! Now I have a much better idea of what I’m doing in R. Thank you very much!!

KULDEEP KURROLIYA says:

Sir, Please post the tutorial for user defined function for Simple Linear Regression in R without using any R packages or library.

HJ Kim says:

great

Roshan Fernando says:

Does anyone have any experience with Version 3.3.0? I am having trouble with the “control R” part and calling data…

Drzhivago11 says:

Very nice! Good job..

Erwan BUREL says:

Many thanks Mr Scherber.

KIM-NDOR DJIMADOUMNGAR says:

A very helpful video for me! Thanks a lot Mr. Scherber. Please would you mind helping me with K-Fold Cross-validation (k = 10) or LOOCV or Validation Set Approach? How to use them to perform regression models, specifically the -kFold CV?
.

Vimal Raj says:

perfect for beginners.. i appreciate your work

Charles Rambo says:

Thank you!

Helmut Dittrich says:

Awesome, thank’s a lot. Very helpful

Charlie says:

I don’t have the data sets

Samukeliso Dlamini says:

After writing data which button u press to pops up data set range plz help me???????

Rebecca Liu says:

Thanks a lot, this is really easy to follow.

Jibreel Ahmad says:

woow! what an incredible tutorial. This the best, I really appreciate your work Christoph :-)

KnorpelDelux says:

Super Video, vielen Dank aus Bayern!

Oluwagbenga Aremu says:

thank you..you have really been of great help to me

Er Td says:

Very helpful tutorial. Any tips on sourcing data directly from an excel spreadsheet(s) to run regressions in R?

VINAYAGAMURTHY JAYARAMAN says:

Easy and good starting point on R

radiazione cosmica di fondo says:

SUPERefficient!!

SagarmathaSipahi says:

I am sure this is a great tutorial but in my case when I use the plot command, it keeps on saying object ‘Ozone’ not found (Please help, if possible):

My editor: data(airquality)
names(airquality)
#Ozone” “Solar.R” “Wind” “Temp” “Month” “Day”
plot(Ozone,Solar.R, data=airquality)

My R Console
> data(airquality)
> names(airquality)
[1] “Ozone” “Solar.R” “Wind” “Temp” “Month”
[6] “Day”
> plot(Ozone,Solar.R)
Error in plot(Ozone, Solar.R) : object ‘Ozone’ not found
> plot(Ozone,Solar.R, data=airquality)
Error in plot(Ozone, Solar.R, data = airquality) :
object ‘Ozone’ not found
>

Junrui Zhang says:

This video is extremely helpful! Thanks a lot! Can I have anther question for you? Assume I have 3 columns. Id,price and date. I want to run regression model between price and date, but under the condition that they have the same id. In another word, I want to see all the regression result that are grouped by different id. What codes should I put there? Wish you could help me! Thanks a lot!

Denis Gris says:

Great lesson ….thank you very much

Dominique Barrette says:

Truly informative, thank you, you explain so well

Nigel Jacobs says:

Thanks so much!

Charles Silber says:

Very very helpful in explaining linear regression. Thank you.

Write a comment

*

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!

Send this to a friend

▷ Other ReviewsVehicles   Show Cars   Motorbikes   Scooters   Rims & Tires   Luxury BoatsFashion   Sunglasses   Luxury Watches   Luxury Purses   Jeans Wear   High Heels   Perfumes   Jewellery   Cosmetics   Shaving Helpers   Fashion HatsFooding   Chef Club   Fooding Helpers   Coktails & LiquorsSports   Sport Shoes   Fitness & Detox   Golf Gear   Racquets   Diving Equipment   Ski Gear   Snowboards   Surf Boards   Rollers & SkatesEntertainment   DIY Guides   Zik Instruments   Published Books   Music Albums   Cine Movies   Trading Helpers   Make Money   Fishing Equipment   Paintball Supplies   Trading Card Games   Telescopes   Knives   VapesHigh Tech   Flat Screens   Tech Devices   Camera Lenses   Printers   USB Devices   PC Hardware   Network Gear   Cloud Servers   Software Helpers   Programmer Helpers   Mobile Apps   Hearing AidsHome   Home Furniture   Home Appliances   Beddings   Floor Layings   Barbecues   Aquarium Gear   Safe Boxes   Office Supplies   Security Locks   Cleaning ProductsKids   Baby Strollers   Child Car Seats   Remote ControlledTravel   Luggages & Bags   Airlines Seats   Hotel Rooms   Fun Trips   Cruise Ships   Mexico Tours