Lab Exercise 1
Lab Exercise 1
Lab Exercise 1
Lab Exercise 1
Q1. Take attitude data set in R and find Summary, Basic stats, histogram, Box
plot and density plot for the column Privileges.
Code:
library(fBasics)
#loading dataset
data(attitude, package="datasets")
data
#basic stats
fBasics::basicStats(data)
#summary
summary(attitude$privileges)
# histogram
hist(attitude$privileges)
#boxplot
boxplot(attitude$privileges)
#density plot
density(attitude$privileges)
plot(density(attitude$privileges))
Register Number: 21BCE5760 Name: Yash Dinesh Singh BMAT202P
Output:
Register Number: 21BCE5760 Name: Yash Dinesh Singh BMAT202P
Histogram ->
Boxplot ->
Register Number: 21BCE5760 Name: Yash Dinesh Singh BMAT202P
Q2. Create a data frame which consist of students details (Name , Age, UG
degree, percentage of marks)
Code:
d
Register Number: 21BCE5760 Name: Yash Dinesh Singh BMAT202P
Output:
Code:
x <- c(65,66,67,67,68,69,70,72)
y <- c(67,68,65,68,72,72,69,71)
Output:
Register Number: 21BCE5760 Name: Yash Dinesh Singh BMAT202P
Q4. A person spends his time on different activities daily (in hours): Draw a pie
chart for this information.
Code:
x <- c(9,1,2,3,7,2)
pie(x, labels)
Output:
Q5. Create bar chart for (i) number of cylinders (ii) number of gears and
(iii)number of Engine(vs) in mtcars data set
Code:
mtcars
A <- table(mtcars$cyl)
B <- table(mtcars$gear)
c <- table(mtcars$vs)
Output:
Register Number: 21BCE5760 Name: Yash Dinesh Singh BMAT202P
Lab Exercise 2
Q1. Create an excel sheet consist of marks of 30 students (0-100 range) of two
subjects and import it and find Summary, Basic stats, histogram, Box plot and
density plot for the imported data.
Code:
library(fBasics)
student_id = 1:30,
# Summary statistics
summary(students_import)
# Basic statistics
fBasics::basicStats(students_import$subject1)
fBasics::basicStats(students_import$subject2)
Register Number: 21BCE5760 Name: Yash Dinesh Singh BMAT202P
# Histogram
hist(students_import$subject1)
hist(students_import$subject2)
# Box plot
boxplot(students_import$subject1)
boxplot(students_import$subject2)
# Density plot
density(students_import$subject1)
plot(density(students_import$subject1))
density(students_import$subject2)
plot(density(students_import$subject2))
Output:
Register Number: 21BCE5760 Name: Yash Dinesh Singh BMAT202P
Register Number: 21BCE5760 Name: Yash Dinesh Singh BMAT202P
Q2. Find the coefficient of correlation between rating and complaints columns
in attitude data set in R. Also find regression line scatter plot.
Code:
library(datasets)
data("attitude")
cor(attitude$rating, attitude$complaints)
plot(attitude$rating, attitude$complaints)
Output:
Register Number: 21BCE5760 Name: Yash Dinesh Singh BMAT202P
Q3. Find correlation matrix, partial correlation matrix and Multiple correlation.
Also find multiple linear regression (Assume that as dependent variable)
Code:
cor_matrix
library(ppcor)
par_cor_matrix
summary(lr1)
summary(lr2)
Register Number: 21BCE5760 Name: Yash Dinesh Singh BMAT202P
summary(lr3)
model <- lm(x3 ~ x1 + x2, data = data) # fit a multiple regression model with
X1 and X2 as independent variables and X3 as dependent variable
Output:
Register Number: 21BCE5760 Name: Yash Dinesh Singh BMAT202P
Register Number: 21BCE5760 Name: Yash Dinesh Singh BMAT202P