Final Cost Practical
Final Cost Practical
STATSTICAL TECHNIQUES
Rayat Shikshan Sanstha’s
CERTIFICATE
Guide
Date: / / 2022
INDEX
No. Details
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.
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"
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
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,] 11 52 32
[2,] 41 15 16
[3,] 17 18 39
T<-t(Matrix2)
print(T)
[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)
> 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.
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
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:
$ 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 ...
$ 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 ...
$ Length : int 177 195 180 193 186 189 200 216 198 206 ...
$ Wheelbase : int 102 115 102 106 109 105 111 116 108 114 ...
$ Weight : int 2705 3560 3375 3405 3640 2880 3470 4105 3495 3620 ...
NULL
Driver only 9 7 11 5 8 3
None 5 0 4 16 3 6
data: car.data
Warning message:
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)
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.
x <- c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131)
# Values of width
print(relation)
Output:-
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
-38.4551 0.6746
lm(formula = y ~ x)
Residuals:
Coefficients:
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
x <- c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131)
print(result)
Output:-
1
76.22869
x <- c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131)
y <- c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48)
png(file = "linearregression.png")
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,
+sub="http://www.federalresers.gov/releases/g19/20050805")
> cor(year,rate)
Output:-[1] -0.9880813