0% found this document useful (0 votes)
23 views3 pages

Procedure For Boxplot, Correlation and Regression in R

1. The document describes creating a boxplot chart using the mtcars data frame to visualize mileage based on the number of cylinders. It specifies creating the chart, saving it as an image file, and getting the resulting boxplot. 2. The document then examines correlations between mileage and other variables in mtcars, finding a negative correlation between mileage and cylinders, a negative correlation between mileage and weight, and a moderate positive correlation between mileage and number of gears. 3. Finally, it formulates a linear regression equation to predict mileage based on weight, finds the coefficients, uses it to predict mileage for a weight of 3.5, and reports the result.

Uploaded by

Joshva Franklin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Procedure For Boxplot, Correlation and Regression in R

1. The document describes creating a boxplot chart using the mtcars data frame to visualize mileage based on the number of cylinders. It specifies creating the chart, saving it as an image file, and getting the resulting boxplot. 2. The document then examines correlations between mileage and other variables in mtcars, finding a negative correlation between mileage and cylinders, a negative correlation between mileage and weight, and a moderate positive correlation between mileage and number of gears. 3. Finally, it formulates a linear regression equation to predict mileage based on weight, finds the coefficients, uses it to predict mileage for a weight of 3.5, and reports the result.

Uploaded by

Joshva Franklin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Problem: Crea ng Boxplot chart using inbuilt data file mtcars

Aim: To create boxplot chart using mpg and cyl fields in mtcars.
Procedure:
1.Men on the path and file name for saving chart.
png("E:/boxplot.png")
2. type code for crea ng boxplot.
boxplot(mpg~cyl,data=mtcars,main="Mileage of cars based on number of cylinders",xlab="No of
cylinders",ylab="mileage per gallon",col=c("red","blue","green"))
3. Type dev.off() to save

Result: Boxplot chart is created and saved


Problem: Study correla on among different variables in mtcars
1. Correla on between mileage and no of cylinders
2. Correla on between mileage and weight
3. Correla on between mileage and gear

Aim: to ascertain the correla on between mileage and other variables in data frame named mtcars

1) Correla on between mileage and no of cylinders


Procedure :-

Mileage=mtcars$mpg
Cylinders=mtcars$cyl
cor(Mileage,Cylinders)

Result:-
-0.852162
There is a nega ve correla on between number of cylinders used and mileage

2)Correla on between mileage and weight

Proedure:
Mileage=mtcars$mpg
Weight=mtcars$wt
cor(Mileage,Weight)

Result:
-0.8676594
There is a nega ve correla on between number of cylinders used and weight of cars

3.Correla on between mileage and gear


Mileage=mtcars$mpg
Gear=mtcars$gear
cor(Mileage,Gear)

Result:
0.4802848
There is a moderate posi ve correla on between number of gears and mileage.
Problem :- Formulate regression equa on between mileage and weight using mtcars data frame and predict
mileage for given weight 3.5

Aim: To formulate regression equa on by trea ng mileage as dependent variable and weight as independent
variable

Procedure:
1. Find coefficients for regression equa on trea ng mileage as dependent variable and mtcars as
independent variable.
M=mtcars$mpg
W=mtcars$wt
L=lm(M~W)
2. Create a data frame with given weight to predict mileage.
W1=data.frame(W=3.5)
3. Predict Mileage using L and W1 using predict()
Predict(variable stored with results of lm func on, data frame with the given value of independent
variable)
predict(L,W1)

Results:
1. Coefficients:
Es mate Std. Error t value Pr(>|t|)
(Intercept) 37.2851 1.8776 19.858 < 2e-16 ***
W -5.3445 0.5591 -9.559 1.29e-10 ***

2. Mileage predicted for given weight 3.5 is 18.57948

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy