0% found this document useful (0 votes)
7 views37 pages

Siddhu R

The document contains practical exercises for a Statistical Analysis course using R Software, completed by a student named Bankar Siddheshwar Adinath. It includes various tasks such as creating vectors, data frames, and visualizations like bar plots and pie charts, as well as calculating measures of central tendency and dispersion. Each practical section provides code snippets and outputs demonstrating the use of R for statistical analysis.
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)
7 views37 pages

Siddhu R

The document contains practical exercises for a Statistical Analysis course using R Software, completed by a student named Bankar Siddheshwar Adinath. It includes various tasks such as creating vectors, data frames, and visualizations like bar plots and pie charts, as well as calculating measures of central tendency and dispersion. Each practical section provides code snippets and outputs demonstrating the use of R for statistical analysis.
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

R Console Page 1

> # ART'S COMMERCE AND SCIENCE COLLEGE,SONAI.


> #
> # DEPARTMENT OF COMPUTER SCIENCE
> #
> # SUBJECT: STATISTICAL ANALYSIS USING R SOFTWARE
> #
> # Name of Student: Bankar Siddheshwar Adinath Batch: A
> #
> # Class:[Link](CS) Date:03 \ 01 \ 2026
> #
> # Practical 1: Introduction to R Software and Basic R commands:
> #
> # Q.1) Create vector v1 = c(10,20,30,40,50).find its length.
> #
> # Answer:
> #
> v1 = c(10,20,30,40,50)
> length(v1)
[1] 5
> #
> # Q.2)Generate v2 using seq function also find its sum.
> #
> # Answer:
> v2 = seq(1,50,by=5)
> v2
[1] 1 6 11 16 21 26 31 36 41 46
> sum(v2)
[1] 235
> #
> # Q.3) Build v3 with characters "CS" and "SPPU" & repeat these characters
> # 3 [Link] v3,count "SPPU" occurances with sum (v3=="SPPU").
> #
> # Answer:
> v3 = c("CS","SPPU")
> v4 = rep(v3,times=3)
> sum = sum(v4=="SPPU")
> sum
[1] 3
> # Alternative code
> v3 = rep(c("CS","SPPU"),TIMES=3)
> rep(v3)
[1] "CS" "SPPU"
> #
> #Q.4)Use scan function with 6 values and find its mean.
> #
> # Answer:
> v5 = scan()
1: 10 20 30 40 50 60
7:
Read 6 items
> v5
[1] 10 20 30 40 50 60
> mean(v5)
[1] 35
> #
> # Q.5)Perform arithmetic: Let a <- c(1:5); b <- c(2,4,6,8,10).
> # compute and display a + b, a * b, a / b
> #
> # Answer:
> a = c(1:5)
> a
[1] 1 2 3 4 5
> b = c(2,4,6,8,10)
> a+b
[1] 3 6 9 12 15
> a*b
[1] 2 8 18 32 50
> a/b
[1] 0.5 0.5 0.5 0.5 0.5
> #
R Console Page 2

> # Q.7)Create vectors with scores 70,85,60,92,78,55


> # Compute total and pass percentage assuming 40% pass marks.
> #
> # Answer:
> scores = c(70,85,60,92,78,55)
> pass_marks = 40
> total = sum(scores)
> total
[1] 440
> passed =sum(scores>=pass_marks)
> passed
[1] 6
> pass_percentage =(passed/length(scores))*100
> pass_percentage
[1] 100
> #
> # *****************************END OF PRACTICAL************************
>
Art's Commerce And Science college Sonai.

Department of [Link] Computer Science

Subject: Statistical Analysis Using R Software

Name of Student: Bankar Siddheshwar Adinath Batch: A


Class: [Link] (Computer Science) Date: 9/01/2026
Practical no 2&3: Diagramatic Representation (bar, pie, histogram, stem and leaf, density plot)
# Q.1) Create data frame with student name ,marks and grades .Display with view data and str
function.
#Answer:
>students = [Link](Name = c("Ram","Shyam","Rita","Gita"),marks = c(85,92,78,65),
Grade= c("A","A","B","c"))
#"View" shows data in a tabular format
> View(students)

> #Str gives data type of each variable,[Link] observations and [Link] variables.
> str(students)
'[Link]': 4 obs. of 3 variables:
$ Name : chr "Ram" "Shyam" "Rita" "Gita"
$ marks: num 85 92 78 65
$ Grade: chr "A" "A" "B" "c"
> #*****************************************************************************

# Q.2) Import CSV file in R console, create bar plot of sales and summary.
> #Answer:
> sales =[Link]("C:/Users/ADMIN/Desktop/[Link]")
> View(sales)

> #To display bar chart use the following code.


> #simple Barplot
> barplot(sales$sales,[Link]=sales$product,
main ="simple bar diagram",
xlab="product",ylab = "sales", col= c("red"))
# Sales in Units
# Interpretation: Laptops in the Mumbai region has highest sales.

# Q.3) Create pie chart showing household budget allocation with percentages. #Data Budget in
('000): 40, 25,20,10,10 # Categories :Rent ,Food,Travel,Enjoy, Savings
#Answer:
> budget = [Link](Budget = c(40,25,20,10,10),
categories = c("Rent","Food","Travel","Enjoy","Savings"))
> View(budget)

> #Percentage of distribution


> pct = round((budget$Budget/sum(budget$Budget))*100,1)
> pct
[1] 38.1 23.8 19.0 9.5 9.5
> #pie chart percentage
> pie= pie(budget$Budget,labels=paste(budget$categories,pct),
main="Monthly Household Budget Distribution",
col= c("red","orange","yellow","blue","green"),radius=0.9)

# Interpretation: Highest expenditure of budget goes for rend which is 38.1


#*****************************************************************************
# Q.4) Generate stem-leaf plot for the following heights data.
150,155,160,162,165,170,172,175,178,180
> #Answer:
> heights =c(150,155,160,162,165,170,172,175,178,180)
> stem(heights)
15 | 05
16 | 025
17 | 0258
18 | 0
> #*****************************************************************************
# Q.5) For the following data of weight draw histogram and stem-leaf plot.
# 55, 60, 58,65,62,70,68,72,75,80,
> #Answer:
> weights= c(55,60,58,65,62,70,68,72,75,80)
> hist(weights,col=c("red"))

# Interpretation: Histogram show a positively skewed data.


> stem(weights)
5 | 58
6 | 0258
7 | 025
8 | 0
> #*****************************************************************************
#Q.6) Create boxplot for the students mark distribution.
> #45,52,68,72,55,78,82,65,91,74,59,83,67,49,76
> #Answer:
> marks =c(45,52,68,72,55,78,82,65,91,74,59,83,67,49,76)
> #Basic Boxplot
> #boxplot(marks,main="Student Marks Distribution")
> boxplot(marks,main="Students Marks Distribution",col="lightblue")
# Interpreation: ________________________________________________________________.
> #****************************************************************************
# Q.7) Draw a density plot for the following data using R
> data = [Link]("C:/Users/Admin/Desktop/Salary_data.csv")
> View(data)

# Density Plot
> plot(density(data$Salary),main = "Density plot of MPG",
xlab = "Miles per Gallon",col =c("red"),lwd=2)

# Interpretation: Interpretation: Density plot shows a positively skewed nature.

Signature of Instructor:______________
*********************************** END OF PRACTICAL ******************************
R Console Page 1

> #*******************************************************************************
> # ART'S COMMERCE AND SCIENCE COLLEGE SONAI
> # Department of [Link] Computer Science
> # subject:Statistical Analysis using R Software
>
> #*******************************************************************************
> #Name: Bankar Siddheshwar Adinath class:[Link](CS)
>
> #Batch: A Date:15/01/2026
>
> #Practical 4:Measures of Central Tendancy(Mean,Mode,Median,Partition Values.
> #*******************************************************************************
> #
> #Q.1)Mean,Mode,Median and Quartiles for the following Ungrouped data
> #45,52,68,72,55,78,82,65,91,74,59,83,67,49,76
> #
> #Answer:
> marks =c(45,52,68,72,55,78,82,65,91,74,59,83,67,49,76)
> #Arithmatic mean
> mean(marks)
[1] 67.73333
> #Median
> median(marks)
[1] 68
> #Mode
> table_marks =table(marks)
> mode = names(table_marks)[[Link](table_marks)]
> mode
[1] "45"
> #Partition values (Quartiles = Q1,Q2,Q3) Q2 = Median
> #0.25 refers Q1, 0.50 refers Q2 and 0.75 refers Q3
> quantile(marks, c(0.25,0.50,0.75))
25% 50% 75%
57 68 77
>
> #*****************************************************************************
> #Q.2)Measures of central tendancy and partition values for a data file .
> data = [Link]("C:/Users/ADMIN/Desktop/Salary_data.csv")
> head(data,5)
YearsExperience Salary
1 1.1 39343
2 1.3 46205
3 1.5 37731
4 2.0 43525
5 2.2 39891
> mean(data$Salary)
[1] 76003
> median(data$Salary)
[1] 65237
> t_marks = table(data$Salary)
> mode1=names(t_marks)[[Link](data$salary)]
> mode1
character(0)
> #Quartile (Q1,Q2,Q3)
> quantile(data$Salary,c(0.25,0.50,0.75))
25% 50% 75%
56720.75 65237.00 100544.75
> #Alternative way to get mean median and all the quartiles expect mode.
> summary(data$Salary)
Min. 1st Qu. Median Mean 3rd Qu. Max.
37731 56721 65237 76003 100545 122391
> #
> #*****************************************************************************
> #Q.3)Measure of central tendancy and partition values for data frames.
> #sample student scores data frame
> df = [Link](
+ Math = c(85,92,78,88,95,76,89,84,91,87),
+ Science = c(79,85,82,90,88,77,86,83,92,80),
+ English = c(88,87,81,89,94,79,85,82,90,86)
+ )
R Console Page 2

> View(df)
> #Central tendancy per column
> sapply(df,mean)
Math Science English
86.5 84.2 86.1
> #Medians
> sapply(df,mean)
Math Science English
87.5 84.0 86.5
> #Mode helper function #Math
> t_marks = table(df$Math)
> mode1=names(t_marks)[[Link](df$Science)]
> mode1
[1] "92"
> #science
> t1_marks = table(df$Math)
> mode2=names(t1_marks)[[Link](df$Science)]
> mode2
[1] "92"
> #English
> t2_marks = table(df$English)
> mode3=names(t2_marks)[[Link](df$English)]
> mode3
[1] "86"
> #Partition values
> quartiles = t(apply(df,2,quantile,prob=c(0.25,0.50,0.75)))
> colnames(quartiles) =c("Q1","Q2","Q3")
> print(quartiles)
Q1 Q2 Q3
Math 84.25 87.5 90.50
Science 80.50 84.0 87.50
English 82.75 86.5 88.75
> #Quick summary
> summary(df)
Math Science English
Min. :76.00 Min. :77.0 Min. :79.00
1st Qu.:84.25 1st Qu.:80.5 1st Qu.:82.75
Median :87.50 Median :84.0 Median :86.50
Mean :86.50 Mean :84.2 Mean :86.10
3rd Qu.:90.50 3rd Qu.:87.5 3rd Qu.:88.75
Max. :95.00 Max. :92.0 Max. :94.00
> #
> #*****************************************************************************
> #
> #Signature of Instructor:
> #
> # END OF PRACTICAL
>
R Console Page 1

> # *****************************************************************************
> # Art's Commerce And Science College , Sonai.
> #
> # Department of [Link] Computer Science.
> #
> # Subject: Statistical Analysis Using R Software
> #
> # Name of Student : Bankar Siddheshwar Adinath Class : [Link](CS)
> #
> # Batch : A Date : 13 / 02 / 2026
> #
> # Practical No.5 : Measures of Dispersion (Range,Variance,SD,Coefficient of
> # Variation,Quartile deviation,Mode)
> #
> # *****************************************************************************
> #
> # Q.1 : Calculate the Mode of the given marks.
> df = [Link](
+ Math = c(85,92,78,88,95,76,89,84,91,88)
+ )
> table_marks = table(df)
> mode = names(table_marks)[[Link](table_marks)]
> mode
[1] "88"
> #
> # Q.2 : Calculate the Range of the given data.
> v1 = c(45,52,68,72,55,78,82,65,91,74,59,83,67,49,76)
> range(v1)
[1] 45 91
> #
> # Range Formula :
> range = max(v1) - min(v1)
> range
[1] 46
> #
> # Q.3 : Calculate the Standard deviation of the given data.
> v2 = c(79,85,82,90,88,77,88,83,92,80)
> std_dev = sd(v2)
> std_dev
[1] 5.015531
> #
> # Q.4 : Calculate the Variance of the given data.
> v3 = c(88,87,81,90,94,79,85,82,90,86)
> variance = var(v3)
> variance
[1] 21.28889
> #
> # Q.5 : Calculate the Mean and Coefficient of the Variation(CV) of the give data.
> v4 = c(34,87,90,45,68,78,55,89,99,77,67,54,69,100)
> mean = mean(v4)
> mean
[1] 72.28571
> #
> # CV Formula :
> cv = (std_dev/mean)*100
> cv
[1] 6.938482
> #
> # Q.6 : Calculate the Interquartile range , First Quartile , Third Quartile and Quartile
> # Deviation using following data.
> # Formula IQR = (Q3 - Q1) / 2
> marks = c(45,52,68,72,55,78,82,65,91,74,59,83,67,49,76)
> IQR(marks)
[1] 20
> #
> # First Quartile
> Q1 = quantile(marks, prob = 0.25)
> Q1
25%
57
R Console Page 2
> #
> # Third Quartile
> Q3 = quantile(marks, prob = 0.75)
> Q3 75%
> 77
> #
> # Quartile Deviation (QD)
> QD = (Q3 - Q1) / 2
> QD 75%
> 10
> #
> # Q.7 : Create a CSV file and Calculate the Mean,Mode,Standard Deviation
> # and Variance.
> data = [Link]("C:/Users/HP/OneDrive/Desktop/student_marks.csv")
> data
Roll_no Name Marks
1 1 Amit 45
2 2 Neha 52
3 3 Rahul 68
4 4 Priya 72
5 5 Anjali 55
6 6 Rohit 78
7 7 Sneha 82
8 8 Karan 65
9 9 Pooja 91
10 10 Arjun 74
> # Mean
> mean(data$Marks)
[1] 68.2
> #
> # Median
> median(data$Marks)
[1] 70
> #
> # Mode
> table_marks = table(data$Marks)
> mode = names(table_marks)[[Link](table_marks)]
> mode
[1] "45"
> #
> # Quartile (Q1,Q2,Q3)
> quantile(data$Marks,
c(0.25,0.50,0.75))
25% 50% 75%
57.5 70.0 77.0
> #
> summary(data$Marks)
Min. 1st Qu. Median Mean 3rd Qu. Max.
45.0 57.5 70.0 68.2 77.0 91.0
> #
> #
*****************************************************************************
**
> #
> # Signature of Instructor : .
> #
> # END OF PRACTICAL
> #
> #
*****************************************************************************
**
>
>
Art's Commerce And Science college Sonai.

Department of [Link] Computer


Science Subject: Statistical
Analysis Using R Software
Name of Student: Bankar Siddheshwar Adinath Batch: A

Class: [Link] (Computer Science) Date: 8 / 4 / 2026

Practical no 6 : Frequency Distribution and Ogive Curve.

# Q.1) Draw Box Plot for mtcars for mpg dataset and identify outliers.

# Answer:
data(mtcars)
> head(mtcars,5)
mpg cyl disp hp drat wt qsec vs am gear
carb

Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4

Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4

Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1

Hornet 4 Drive 21.4 6 258 110 3.0 3.215 19.44 1 0 3 1


8
Hornet 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Sportabout

> str(mtcars)
'[Link]': 32 obs. of 11 variables:

$ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...

$ cyl : num 6 6 4 6 8 6 8 4 4 6 ...

$ disp: num 160 160 108 258 360 ...

$ hp : num 110 110 93 110 175 105 245 62 95 123 ...

$ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...

$ wt : num 2.62 2.88 2.32 3.21 3.44 ...

$ qsec: num 16.5 17 18.6 19.4 17 ...

$ vs : num 0 0 1 1 0 1 0 1 1 1 ...

$ am : num 1 1 1 0 0 0 0 0 0 0 ...

$ gear: num 4 4 4 3 3 3 3 4 4 4 ...


$ carb: num 4 4 1 1 2 1 4 2 2 4 ...
> boxplot(mtcars$mpg,
main = "Boxplot of
MPG", ylab = "Miles
Per Gallon")

# Interpretation : The median MPG is about 18 , and most values lie between 14
and 22 MPG.

> #****************************************************************************
# Q.2) Create frequency distribution table. for 100 random numbers 0-
100,count bins 0-10,..., 90-100 and give it table and barplot.
> #Answer:
> rand = sample(0:100,100)
> bins = cut(rand , breaks = seq(0,100,10))
> # bins
> bins
[1] (60,70] (30,40] (60,70] (70,80] (30,40] (80,90] (90,100] (30,40]

[9] (80,90] (60,70] (40,50] (60,70] (20,30] (90,100] (0,10] (50,60]

[17] (30,40] (20,30] (70,80] (90,100] (20,30] (40,50] (30,40] (40,50]

[25] (80,90] (30,40] (30,40] (10,20] (10,20] (90,100] (20,30] (40,50]

[33] (40,50] (80,90] (40,50] (30,40] (60,70] (30,40] (20,30] (10,20]

[41] (10,20] (90,100] (80,90] (20,30] (50,60] (60,70] (70,80] (90,100]

[49] (0,10] (70,80] (0,10] (10,20] (10,20] (80,90] (60,70] (0,10]

[57] (90,100] (0,10] (10,20] (60,70] (60,70] (80,90] (50,60] (70,80]

[65] (50,60] (40,50] (10,20] (0,10] (70,80] (70,80] (20,30] (90,100]

[73] (70,80] (80,90] (40,50] (40,50] (50,60] (10,20] (70,80] (50,60]

[81] (0,10] (90,100] (20,30] (0,10] (10,20] <NA> (50,60] (50,60]

[89] (40,50] (0,10] (80,90] (80,90] (50,60] (20,30] (0,10] (20,30]

[97] (70,80] (90,100] (60,70] (30,40]

10 Levels: (0,10] (10,20] (20,30] (30,40] (40,50] (50,60] (60,70] ... (90,100]

> barplot(table(bins))
# Interpretation : The data is evenly distributed , with a slight dip in the
(60,70) interval.

> #****************************************************************************
*

# Q.3) Create two vectors make a dataframe of them and then identify duplicate
and the unique elements for the dataframe. vecl = 1:5 , vec2 =
c("a","b","c","d","e")

#Answer:
> vec1 = 1.5
> vec2 = c("a","b","c","d","e")
> df = [Link](vec1 , vec2)
> df
vec1 vec2
1 1.5 a
2 1.5 b
3 1.5 c
4 1.5 d
5 1.5 e
> duplicated(df)
[1] FALSE FALSE FALSE FALSE FALSE
> unique(d
f) vec1
vec2
1 1.5 a
2 1.5 b
3 1.5 c
4 1.5 d
5 1.5 e
#*****************************************************************************
# Q.4) Create data frame for 5 employees (Name,Gender,Age,Designation) and
short by name [Link] the data frame also
> #Answer:
> employees = [Link](
Name = c("Anita","Ravi","Sunil","Meera","Kiran"),
Gender =
c("Female","Male","Male","Female","Male"),
Age = c(28 , 35 , 40 , 30 , 25),
Designation=c("Analyst","Manger","Developer","HR","Intern")
)
> # View the original data frame
> print(employees)
Name Gender Age Designation
1 Anita Female 28 Analyst
2 Ravi Male 35 Manger
3 Sunil Male 40 Developer
4 Meera Female 30 HR
5 Kiran Male 25 Intern
> # Sort by Name in ascending order
> sorted_employees = employees[order(employees$Name),]
> sorted_employees
Name Gender Age Designation
1 Anita 28 Analyst
Female
5 Kiran 25 Intern
Male
4 Meera 30 HR
Female
2 Ravi 35 Manger
Male
3 Sunil 40 Develope
Male r
> # View the sorted data frame
> print(sorted_employees)
Name Gender Age
Designation 1 Anita
Female 28 Analyst
5 Kiran Male 25 Intern
4 Meera Female 30 HR
2 Ravi Male 35 Manger
3 Sunil Male 40 Developer
#*****************************************************************************
> # Q.5) Write R program to extract first 10 English letters in lower case,
last 10 in upper case, and letters 22nd to 24th in upper case.
> # Answer :
# first 10 English letters in lower case
> letters_lower = tolower(letters[1:10])
> print(letters_lower)
[1] "a" "b" "c" "d" "e" "f"
"g" "h" "i" "j" #
# last 10 in upper case
> letters_upper_last = toupper(letters[22:24])
> print(letters_upper_last)
[1] "V" "W"
"X" #
# letters 22nd to 24th in upper case
> letters_upper_mid = toupper(letters[22:24])
> print(letters_upper_mid)
[1] "V" "W" "X"
>#
*****************************************************************************
***** # Q.6) For the following data draw more than ogive curve .Length(cm):
5-10 10-15 15-20 20-25 25-30 30-35 35-40 , [Link] Screw: 2 7 16 34
13 6 2
> # Answer :
# To draw more than cumulative frequency curve
> # lower limits
> lower_limits = c(5,10,15,20,25,30,35)
> # frequency
> f = c(2,7,16,34,13,6,2)
>#
> # More than cumulative frequency curve (mtcf)
> mtcf = rev(cumsum(rev(f)))
> mtcf
[1] 80 78 71 55 21 8 2
> # To add one lower limit at the end which is 40 width mtcf 0
> mtcf = c(mtcf,0)
> mtcf
[1] 80 78 71 55 21 8 2 0
> lower_limits = c(lower_limits,40)
> lower_limits
[1] 5 10 15 20 25 30 35 40
> # more than cumulative frequency curve
> plot(lower_limits,mtcf,type="o",xlab="
lower limits", ylab="mtcf",main="mtcf
curve",col="red")
# Interpretation : The mtcf value steadily decreases as the
lower limits increase. # Less than cumulative frequency curve
> # upper limits
> upper_limits = c(10,15,20,25,30,35,40)
> # Less than cumulative frequency curve (mtcf)
> ltcf = cumsum(f)
> ltcf
[1] 2 9 25 59 72 78 80
>#
> # To add one upper limits before 10 which is 0 with ltcf 0
> upper_limits = c(0,upper_limits)
> upper_limits
[1] 0 10 15 20 25 30 35 40
> ltcf = c(0,ltcf)
> ltcf
[1] 0 2 9 25 59 72 78 80
>#
> plot(upper_limits,ltcf,type="o",xlab="
upper limits", ylab="ltcf",main="ltcf
curve",col="red")

# Interpretation : The ltcf value steadily increases as the upper limits


increase.

>#
*****************************************************************************
*****
# Q.7) Draw less than and more than ogive curves for the following data and
find the median values. [Link] children : 0 1 2 3 4 5 , [Link] families : 50
172 119 32 8 1. Data

> # Answer:
> children = c(0 , 1, 2 ,3 ,4, 5 )
> families = c(50, 172,
119, 32 ,8, 1) # Total
Families
> N = sum(families)
>N
[1] 382
>#
> # Less than cumulative frequency
> less_cf = cumsum(families)
> less_cf
[1] 50 222 341 373 381 382
>#
> # more than cumulative frequency
> more_cf = rev(cumsum(rev(families)))
> more_cf
[1] 382 332 160 41 9 1
>#
> # Plot less than ogive
> plot(children,less_cf,type="o",col="blue",xlab="[Link] children",
+ ylab="cumulative frequency",main="less than ogive")
>#
> # Plot more than ogive
> plot(children,more_cf,type="o",col="red",xlab="[Link] children",
+ ylab="cumulative frequency",main="more than ogive")
# Interpretation : The cumulative frequency decreases as the number of children increases.
> # **********************************************************************************
>#
> # Signature of Instructor : .
>#
># END OF PRACTICAL
>#
#************************************************************************************
Art's Commerce And Science college Sonai.

Department of [Link] Computer

Science Subject: Statistical

Analysis Using R Software

Name of Student: Bankar Siddheshwar Adinath Batch: A

Class: [Link] (Computer Science) Date: 28 / 3 / 2026

Practical no 7 : Correlation

# Q.1) Draw the relationship between [Link] and [Link] of the Iris
dataset using scatter plot.

#Answer:

> data(iris)

> str(iris)

'[Link]': 150 obs. of 5 variables:

$ [Link]: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...

$ [Link] : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...

$ [Link]: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...

$ [Link] : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...

$ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...

> plot(iris$Sepal.
Length,
iris$[Link]
h,
main="Sepal Length vs Sepal

Width", xlab="Sepal Length",


ylab="Sepal
Width",
col="red",

pch=19)

> abline(lm(iris$[Link] ~

iris$[Link]), col="blue",

lwd=2)
# Interpretation : The scatter plot shows a weak negative relationship between
Sepal Length and Sepal Width.

> cor(iris_df$SepalLength, iris_df$SepalWidth)

[1] -0.1175698

> #*****************************************************************************
# Q.2) The Marks obtained by two students in Subject A :
54,56,78,21,45,32,78,53,65,54 & B :
32,46,62,27,49,59,90,76,43,65. Draw scatter and find
correlation.

> #Answer:

> A = c(54,56,78,21,45,32,78,53,65,54)

> B = c(32,46,62,27,49,59,90,76,43,65)

>#

> #Scatter Plot

> plot(A,B,

col="red",
pch=19,
main="Scatter Plot of A
vs B", xlab="Marks A",

ylab="Marks B")

>#

> # Regression line

> abline(lm(B~A), col="blue", lwd=2)

>#
# Interpretation : The scatter plot shows a positive relationship between Marks A and
Marks B.

> # Correlation

> cor(A,B)

[1] 0.5466082

> #*****************************************************************************
# Q.3) Study Hours : 5,7,3,8,6,9 & Scores : 80,85,60,90,75,95. Draw a scatter
plot and find the correlation between study hours and scores using the Pearson
method.

#Answer:

> Study_Hours = c (5,7,3,8,6,9)

> Scores = c (80,85,60,90,75,95)

> # Scatter Plot

> plot(Study_Ho
urs, Scores,
col="purple"
, pch=19,
main="Study_Hours vs

Scores",
xlab="Study_Hours",
ylab="Scores")

> # Regression Line

> abline(lm(Scores~Study_Hours), col="black", lwd=2)


# Interpretation: The graph shows a positive linear relationship between Study_Hours
and Scores.

> # Pearson Correlation

> cor(Study_Hours,Scores,method="pearson")

[1] 0.9569094

#*****************************************************************************
# Q.4) The demand (20, 32, 45, 21, 19, 23, 47, 67, 34) and supply (16, 38, 54, 25, 20,
20, 42, 66, 40)
data are given; draw a scatter plot and find the correlation using the Spearman method.

> #Answer:

> Demand = c (20,32,45,21,19,23,47,67,34)

> Supply = c (16,38,54,25,20,20,42,66,40)

> # Scatter Plot

> plot(Deman
d, Supply,
col="orang
e",
pch=19,
main="Demand vs
Supply",
xlab="Demand",
ylab="Supply")

> # Regression Line

> abline(lm(Supply~Demand), col="blue", lwd=2)


# Interpretation: The graph indicates a positive relationship between demand and
supply.

> # Spearman Correlation

> cor(Demand,Supply,method="spearman")

[1] 0.9288784

#> #*****************************************************************************
> # **************************************************************************

>#

> # Signature of Instructor : .

>#

># END OF PRACTICAL

>#

> #***************************************************************************

>
R Console Page 1

> # *****************************************************************************
> #
> # Art's Commerce And Science College , Sonia.
> #
> # Department of [Link] Computer Science .
> #
> # Subject : Statistical Analysis Using R Software.
> #
> # Name of Student : Bankar Siddheshwar Adinath Batch : A
> #
> # Class : [Link](Computer Science). Date : 1 / 4 / 2026
> #
> # Practical No. 8 : Regression.
> #
> # ***************************************************************************
> #
> # Q.1) Soil depth X : 1.8,1.9,2.5,1.4,1.3,2.1,2.3 ; Yield
> # Y : 200,270,450,160,90,440,380. Regression y on x , estimate y at x = 2
> # Answer :
> X = c(1.8,1.9,2.5,1.4,1.3,2.1,2.3)
> Y = c( 200,270,450,160,90,440,380)
> #
> # Regression equation : y = a + bx
> model = lm(Y ~ X)
> #
> # Predication of y values for the given value of x
> predict(model , [Link](X = 2))
1
314.4552
> # Regression equation
> # Y = -288.9 + 301.7X
> #
> # Q.2) Load iris dataset and determine the regression equation of [Link] on [Link].
> # Estimate [Link] when [Link] = 3.1.
> data(iris)
> head(iris,5)
[Link] [Link] [Link] [Link] Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
4 4.6 3.1 1.5 0.2 setosa
5 5.0 3.6 1.4 0.2 setosa
> model = lm([Link] ~ [Link] , data = iris)
> model

Call:
lm(formula = [Link] ~ [Link], data = iris)

Coefficients:
(Intercept) [Link]
3.41895 -0.06188

> new_x= [Link]([Link] = 3.1)


> Ypre=predict(model,new_x)
> Ypre
1
3.227104
> #
> # Regression equation
> # [Link] = 3.41895 - 0.06188([Link])
> #
> # Q.3) Determine the regression equation of y on x. also estimate y when x = 25.
> # Demand : 20,32,45,21,19,23,47,67
> # Supply : 16,38,54,25,20,42,66,40.
> # Answer :
> x = c(20,32,45,21,19,23,47,67)
> y = c(16,38,54,25,20,42,66,40)
> model = lm( y ~ x )
> model
R Console Page 2

Call:
lm(formula = y ~ x)

Coefficients:
(Intercept) x
16.1973 0.6256
> predict(model , [Link](x=25)) 1
> 31.83795#
> # Regression equation
> # Y = 16.1973 + 0.6256X
> #
> #*************************************************************************
***
> #
> # Sign of Instructor :
> #
> # END OF PRACTICAL
> #*************************************************************************
**
>
>
>
Art's Commerce And Science college Sonai.

Department of [Link] Computer

Science Subject: Statistical Analysis

Using R Software

Name of Student: Bankar Siddheshwar Adinath


Batch: A

Class: [Link] (Computer Science) Date:

Practical No.9 : Discrete Probability Distributions ( Binomial , Poisson )


.

# Q.1) A factory produces light bulbs with a 5% defect rate.


# a) Simulate 100 inspections ( 1 = defective , 0 = non-defective ).
# b) Estimate the proportion of defective bulbs from the simulation.

> # Answer:

> a) Simulation : Generating 100 observations


> [Link](123)
> x <- rbinom(100,size=1,prob=0.05)
>x
[1] 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0
0 0
[38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0
[75] 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0

> b) Estimated proportion


> n= length(x)
>n
[1] 100

> mean(x)
[1] 0.05

# OR
> mean = sum (x) / n
> mean
[1] 72.28571

> #*************************************************************************
****

# Q.2) Each student passes an exam with probability 0.6. A class has 12
students.
> # a) What is the probability exactly 8 students pass ? (dbinom)
> # b) What is the probability at least 9 pass ? (pbinom)
> # c) What is the probability at most 5 pass ?
> # d) Simulate 100 such classes and estimate P(X ≥ 9).
> # e) Find the 90th percentile of the number of students passing.
> # Answer :

> # n = 12 , p = 0.6
> # a) P(X=8)
> dbinom(8,12,0.6) # dbinom(x,n,p)
[1] 0.2128409

> # b) P(X>=9) = 1-P(X<=8)


> 1-pbinom(8,12,0.6)
[1] 0.2253373

> # c) P(X<=5) # at most 5 students pass


> pbinom(5,12,0.6)
[1] 0.1582123

> # d) Generating 100 random observations


> [Link](123)
> sim = rbinom(100,size=12,prob=0.6)
> sim
[1] 8 6 8 5 5 10 7 5 7 7 4 7 6 7 9 5 8 10 8 4 5 6 7 3 7
[26] 6 7 7 8 9 4 5 6 6 10 7 6 9 8 8 9 8 8 8 9 9 8 7 8 5
[51] 10 7 6 9 7 9 9 6 5 8 7 9 8 8 6 7 6 6 6 7 6 7 6 12 7
[76] 9 8 7 8 9 8 6 8 6 9 8 3 5 5 9 9 7 8 7 8 9 6 9 7 7

> # e) Estimated Probability P(X = 9)using simulation


> mean(sim>=9)
[1] 0.22

> #*************************************************************************
*****

# Q.3) A vaccine works with probability 0.85. It is given to 20 patients.


> # Probability between 16 and 19 . P(16 <= X <= 19) .
> # a) Calculate mean and standard deviation theoretically .
> # b) Determine the ( median , Q1 , Q2 , Q3 ) .
> # c) Generate 5000 simulations and plot a histogram.

> # Answer :

> # 1) P(16 < X < 19) = P(X<19) – P(X<16)


> pbinom(18,20,0.85) - pbinom(15,20,0.85)
[1] 0.654289

> # 2) P(16 <= X <= 19)


> sum(dbinom(16:19,20,0.85))
[1] 0.7910873
> # a) mean and standard deviation
> n = 20
> p = 0.85
> # mean
> n*p
[1] 17
> # standard deviation
> sqrt(n*p*(1-p))
[1] 1.596872

> # b) Median , Q1 , Q2 , Q3 .
> # median
> qbinom(0.5,20,0.85)
[1] 17
> # Q1
> qbinom(0.25,20,0.85)
[1] 16
> # Q2
> qbinom(0.50,20,0.85)
[1] 17
> # Q3
> qbinom(0.75,20,0.85)
[1] 18

> # c) Histogram
> [Link](123)
> sim = rbinom(5000,20,0.85)
> hist(sim ,col = "lightblue")
> #*************************************************************************
******

# Q.4) A hospital receives an average of 4 emergency cases per hour.


> # a) Probability of exactly 6 cases in one hour.
> # b) Probability of fewer than 3 cases.
> # c) Probability of more than 5 cases.
> # d) Simulate 100 hours and estimate the average number of cases.
> # e) Find the 95th percentile of hourly cases.

> # Answer :

> # a) P(X=6)
> dpois(6,4)
[1] 0.1041956

> # b) P(X < 6) = P(X <= 5)


> ppois(5,4)
[1] 0.7851304

> # c) P(X > 5) = 1-P(X<=5)


> 1-ppois(5,4)
[1] 0.2148696

> # d)
> [Link](123)
> sim = rpois(100,4) # Random number generation # rpois(100,lambda)
> mean(sim)
[1] 4.09
> hist(sim)
> # e) 95th percentile
> qpois(0.95,4)
[1] 8

>#**************************************************************************
******

# Q.5) A website receives an average of 10 visitors per minute.


> # a) Probability of at most 8 visitors.
> # b) Probability of at least 10 visiters.
> # c) Determine median.
> # Answer :
> # a) P(X<=8)
> ppois(8,10)
[1] 0.3328197

> # b) P(X>=10) = 1-P(X<=9)


> 1-ppois(9,10)
[1] 0.5420703

> # c) Median
> qpois(0.5,10)
[1] 10

Signature of Instructor:

*********************************** END OF PRACTICAL


******************************

You might also like