0% found this document useful (0 votes)
41 views29 pages

Final Cost Practical

Uploaded by

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

Final Cost Practical

Uploaded by

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

COMPUTER ORIENTED

STATSTICAL TECHNIQUES
Rayat Shikshan Sanstha’s

Mahatma Phule Arts, Science & Commerce College,


Panvel, Dist. Raigad

Reaccredited by NAAC at A grade with CGPA of 3.18


“Best College Award” by University of Mumbai
Founder: DR. Karmveer Bhaurao Patil, D.Lit.

CERTIFICATE

I, Asst. Prof. Kalyani Patil here by certify that Mr ., Exam No: ,


student of Rayat Shikshan Saqnstha’s Mahatma Phule Arts, Science &
Commerce College, Panvel has completed a practical “COMPUTER ORIENTED
STATSTICAL TECHNIQUES” in the academic year of 2021-22. The Work of the
student is original and the information included in the project is True to the
best my Knowledge.

Internal Head of Department

Guide

Date: / / 2022
INDEX

No. Details

1 Using R executes the basic commands, array, list and frames.

2 Create a Matrix Using R and perform the operations addition,


inverse, transpose and multiplication operations.

3 Using R executes the statistical function: mean, median, mode,


quartiles, range, inter quartile range, histogram. Using R import the
data from excel file

4 Using R import the data from excel/.CSV file calculate the standard
deviation, variance, co-variance.

5 Using R import the data from excel/.CSV file and draw the skewness.

6 Using R import the data from excel/.CSV file and perform the
hypothetical testing.
7 Using R import the data from excel/.CSV file perform the Chi-squared
Test.

8 Using R perform binomial and normal distribution.

9 Using R linear regression using R

10 Compute the linear least square regression


Practical 1
Question : Using R executes the basic commands, array, list and
frames.For Basic commands:

The Basic commands:-

For create List:-


For Array:-

Data Frames:-
Control Statement :-
If statement:-
a <- 33
b <- 200
if (b > a)
{
print("b is greater than a")
}
Output:- "b is greater than a"

If…..else statement:-
a <- 200
b <- 33
if (b > a)
{
print("b is greater than a")
} else if (a == b) {
print("a and b are equal")
} else { print("a is greater than b")
}
Output :-"a is greater than b"

Switch case statement :-


x <- switch( 3,
+ "first",
+ "second",
+ "third",
+ "fourth"
+)
> print(x)

Output:-"third"

Looping statement:-
While loop:-
i <- 1
> while (i < 6) {
+ print(i)
+ i <- i + 1
+}

Output:- [1] 1
[1] 2
[1] 3
[1] 4
[1] 5

For Loop:-
for (x in 1:10) {
+ print(x)
+}

Output:-
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
[1] 6
[1] 7
[1] 8
[1] 9
[1] 10

Loop control statement:


Break statement:
fruits <- list("apple", "banana", "cherry")
for (x in fruits) {
+ if (x == "cherry") {
+ break
+}
+ print(x)
+}
Output:-
[1] "apple"
[1] "banana"

Next Statement:
fruits <- list("apple", "banana", "cherry")
for (x in fruits) {
+ if (x == "banana") {
+ next
+}
+print(x)
+}
Output:-
[1] "apple"
[1] "cherry"
Practical 2
Question:- Create a Matrix Using R and perform the
operations addition, inverse, transpose and multiplication
operations.
Transpose operation:-

Matrix2 = matrix(c(11,52,32,41,15,16,17,18,39),nrow=3,ncol=3,byrow=TRUE)

print(Matrix2)

Output:-

[,1] [,2] [,3]

[1,] 11 52 32

[2,] 41 15 16

[3,] 17 18 39

T<-t(Matrix2)

print(T)

[,1] [,2] [,3]

[1,] 11 41 17

[2,] 52 15 18

[3,] 32 16 39

Practical 3
Question:- Using R executes the statistical function: mean, median,
mode, quartiles, range, inter quartile range, histogram. Using R
import the data from excel file
Create the histogram:-
# Create data for the graph.

> v <- c(19, 23, 11, 5, 16, 21, 32, 14, 19, 27, 39)

# Create the histogram.

> hist(v, xlab = "No.of Articles ", col = "green", border = "black")
Practical 4
Question:- Using R import the data from excel/.CSV file calculate
the standard deviation, variance, co-variance
Practical 5
Question :-Using R import the data from excel/.CSV file and draw
the skewness.

Example:- Seema is interested on the elapse time she


spend on riding a tricycle from home to scholl for three
weeks. She obtain the following data.
19.09,19.55,17.89,17.73,25.15,27.27,25.24,21.65,20.92,22.61
,15.71,22.04,22.60,24.25
Compute and interpreat the skewness and kurtosis.

Code:-
>time<c(19.09,19.55,17.89,17.73,25.15,27.27,25.24,21.65,20.92,22.61,15.71,2
2.04,22.60,24.25)

> library(moments)
> skewness(time)
> kurtosis(time)
Output:-
[1] -0.04637707
[1] 2.155984
Practical 6

Question:- Using R import the data from


excel/.CSV file and perform the hypothetical testing.

Practical 7
Question:- Using R import the data from excel/.CSV file perform
the Chi-squared Test.
Example:- we will take the Cars93 data in the “MASS” library which
represents the sales of different models of cars in the year 1993.

>library("MASS")
>print(str(Cars93))
Output:-
'data.frame': 93 obs. of 27 variables:

$ Manufacturer : Factor w/ 32 levels "Acura","Audi",..: 1 1 2 2 3 4 4 4 4 5 ...

$ Model : Factor w/ 93 levels "100","190E","240",..: 49 56 9 1 6 24 54


74 73 35 ...

$ Type : Factor w/ 6 levels "Compact","Large",..: 4 3 1 3 3 3 2 2 3 2 ...

$ Min.Price : num 12.9 29.2 25.9 30.8 23.7 14.2 19.9 22.6 26.3 33 ...

$ Price : num 15.9 33.9 29.1 37.7 30 15.7 20.8 23.7 26.3 34.7 ...

$ Max.Price : num 18.8 38.7 32.3 44.6 36.2 17.3 21.7 24.9 26.3 36.3 ...

$ MPG.city : int 25 18 20 19 22 22 19 16 19 16 ...

$ MPG.highway : int 31 25 26 26 30 31 28 25 27 25 ...

$ AirBags : Factor w/ 3 levels "Driver & Passenger",..: 3 1 2 1 2 2 2 2 2


2 ...

$ DriveTrain : Factor w/ 3 levels "4WD","Front",..: 2 2 2 2 3 2 2 3 2 2 ...

$ Cylinders : Factor w/ 6 levels "3","4","5","6",..: 2 4 4 4 2 2 4 4 4 5 ...

$ EngineSize : num 1.8 3.2 2.8 2.8 3.5 2.2 3.8 5.7 3.8 4.9 ...

$ Horsepower : int 140 200 172 172 208 110 170 180 170 200 ...

$ RPM : int 6300 5500 5500 5500 5700 5200 4800 4000 4800 4100 ...
$ Rev.per.mile : int 2890 2335 2280 2535 2545 2565 1570 1320 1690
1510 ...

$ Man.trans.avail : Factor w/ 2 levels "No","Yes": 2 2 2 2 2 1 1 1 1 1 ...

$ Fuel.tank.capacity: num 13.2 18 16.9 21.1 21.1 16.4 18 23 18.8 18 ...

$ Passengers : int 5 5 5 6 4 6 6 6 5 6 ...

$ Length : int 177 195 180 193 186 189 200 216 198 206 ...

$ Wheelbase : int 102 115 102 106 109 105 111 116 108 114 ...

$ Width : int 68 71 67 70 69 69 74 78 73 73 ...

$ Turn.circle : int 37 38 37 37 39 41 42 45 41 43 ...

$ Rear.seat.room : num 26.5 30 28 31 27 28 30.5 30.5 26.5 35 ...

$ Luggage.room : int 11 15 14 17 13 16 17 21 14 18 ...

$ Weight : int 2705 3560 3375 3405 3640 2880 3470 4105 3495 3620 ...

$ Origin : Factor w/ 2 levels "USA","non-USA": 2 2 2 2 2 1 1 1 1 1 ...

$ Make : Factor w/ 93 levels "Acura Integra",..: 1 2 4 3 5 6 7 9 8 10 ...

NULL

#create a data frame from the main data set.


> car.data<-data.frame(Cars93$AirBags,Cars93$Type)
> #create a table with the neede variable.
> car.data =table(Cars93$AirBags,Cars93$Type)
> print(car.data)
Compact Large Midsize Small Sporty Van

Driver & Passenger 2 4 7 0 3 0

Driver only 9 7 11 5 8 3

None 5 0 4 16 3 6

> #perfrom the Chi-Square test.


> print(chisq.test(car.data))
Output:-
Pearson's Chi-squared test

data: car.data

X-squared = 33.001, df = 10, p-value = 0.0002723

Warning message:

In chisq.test(car.data) : Chi-squared approximation may be incorrect

Practical 8
Question:-Using R perform binomial and normal
distribution.
R-Binomial Distribution:-
dbinom(x, size, prob)
pbinom(x, size, prob)
qbinom(x, size, prob)
rbinom(x, size, prob)
dbinom():- This function gives the probability distributuion at
each point.

pbinom():-
#probability of getting 26 or less heads from a 51 tosses of a coin.

> x<-pbinom(26,51,0.5)

> print(x)

Output:- [1] 0.610116

qbinom():-
> #how many heads will have a probability of 0.25 will come out
when a coin is tossed 51 time

> x<-qbinom(0.25,51,1/2)

> print(x)

Output:-[1] 23

rbinom():-
# Find 8 random values from a sample of 150 with probability of 0.4.

x <- rbinom(8,150,4)

print(x)

Output:-[1] 57 65 56 69 71 53 48 62

Practical 9
Question:- Perform the linear regression using R
Input Data :-
# Values of height

151, 174, 138, 186, 128, 136, 179, 163, 152, 131

# Values of weight.

63, 81, 56, 91, 47, 57, 76, 72, 62, 48


A.Create Relationship Model & get the Coefficients
# Values of height

x <- c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131)

# Values of width

y <- c(63,81, 56, 91, 47,57, 76, 72, 62, 48)

# Apply the lm()function.

relation <- lm(y~x)

print(relation)

Output:-
Call:

lm(formula = y ~ x)

Coefficients:

(Intercept) x

-38.4551 0.6746

B.Get the Summary of the Relationship# Values of height


# Values of height
x <- c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131)
# Values of width
y <- c(63,81, 56, 91, 47,57, 76, 72, 62, 48)
# Apply the lm()function.
relation <- lm(y~x)
print(summary(relation))
Output:-
Call:

lm(formula = y ~ x)

Residuals:

Min 1Q Median 3Q Max

-6.3002 -1.6629 0.0412 1.8944 3.9775

Coefficients:

Estimate Std. Error t value Pr(>|t|)

(Intercept) -38.45509 8.04901 -4.778 0.00139 **

x 0.67461 0.05191 12.997 1.16e-06 ***

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 3.253 on 8 degrees of freedom

Multiple R-squared: 0.9548, Adjusted R-squared: 0.9491

F-statistic: 168.9 on 1 and 8 DF, p-value: 1.164e-06

C)Predict the weight of new persons :-


# The predictor vector.

x <- c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131)

# The resposne vector.


y <- c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48)

# Apply the lm() function.

relation <- lm(y~x)

# Find weight of a person with height 170.

a <- data.frame(x = 170)

result <- predict(relation,a)

print(result)

Output:-
1

76.22869

D)Visualize the Regression Graphically:-


# Create the predictor and response variable.

x <- c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131)

y <- c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48)

relation <- lm(y~x)

# Give the chart file a name.

png(file = "linearregression.png")

# Plot the chart.

plot(y,x,col = "blue",main = "Height & Weight Regression",

abline(lm(x~y)),cex = 1.3,pch = 16,xlab = "Weight in Kg",ylab =


"Height in
cm")

# Save the file.

dev.off()

Practical 10
Question:-Compute the linear least square regression
>year<-c(2000,2001,2002,2003,2004)

> rate<-c(9.34,8.50,7.62,6.93,6.60)

> plot(year,rate,

+ main="Commerical Banks Interest Rate for 4 years Car Loan",

+sub="http://www.federalresers.gov/releases/g19/20050805")

> cor(year,rate)

Output:-[1] -0.9880813

You might also like