0% found this document useful (0 votes)
18 views4 pages

Practical 4 DS

Uploaded by

ayushsonar2001
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)
18 views4 pages

Practical 4 DS

Uploaded by

ayushsonar2001
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/ 4

> #Q1

> X <- c(11.1, 10.3, 12.0, 15.1, 13.7, 18.5, 17.3, 14.2, 14.8, 15.3)

> Y <- c(10.9, 14.2, 13.8, 21.5, 13.2, 21.1, 16.4, 19.3, 17.4, 19.0)

> spearman_corr <- cor(X, Y, method = "spearman")

> print(spearman_corr)

[1] 0.6969697

> pearson_corr <- cor(X, Y, method = "pearson")

> print(pearson_corr)

[1] 0.7317151

>

> #Q2

> X <- c(34, 37, 36, 32, 32, 36, 35, 34, 29, 35)

> Y <- c(37, 37, 34, 34, 33, 40, 39, 37, 36, 35)

> model <- lm(X ~ Y)

> model

Call:

lm(formula = X ~ Y)

Coefficients:

(Intercept)

18.9167 0.4167
>

> #Q3

> Sales <- c(50, 50, 55, 60, 65, 65, 65, 60, 60, 50)

> Expenses <- c(11, 13, 14, 16, 16, 15, 15, 14, 13, 13)

> Advertising <- c(24, 42, 43, 54, 54, 27, 35, 34, 39, 42)

> data <- data.frame(Sales, Expenses, Advertising)

> model <- lm(Sales ~ Expenses + Advertising, data = data)

> model

Call:

lm(formula = Sales ~ Expenses + Advertising, data = data)

Coefficients:

(Intercept) Expenses Advertising

9.0281 4.4264 -0.3299

>

> #Q4

> n <- 15

> p <- 0.1

> P_X_3 <- dbinom(3, n, p)

> print(P_X_3)

[1] 0.1285054

> P_X_7 <- dbinom(7, n, p)

> print(P_X_7)

[1]

0.0002770056

> P_X_leq_7 <- pbinom(7, n, p)


> print(P_X_leq_7)

[1] 0.9999664

> P_X_geq_8 <- 1 - pbinom(7, n, p)

> print(P_X_geq_8)

[1] 3.362489e-05

> x_value <- qbinom(0.4, n, p)

> print(x_value)

[1] 1

>

> #Q5

> mean <- 30

> sd <- 5

> P_X_leq_40 <- pnorm(40, mean, sd)

> print(P_X_leq_40)

[1] 0.9772499

> P_X_leq_56 <- pnorm(56, mean, sd)

> print(P_X_leq_56)

[1] 0.9999999

> P_X_gt_50 <- 1 - pnorm(50, mean, sd)

> print(P_X_gt_50)

[1] 3.167124e-05

> P_25_leq_X_leq_35 <- pnorm(35, mean, sd) - pnorm(25, mean, sd)

> print(P_25_leq_X_leq_35)

[1] 0.6826895

>

> #Q6

>

> Sales_A <- c(100, 120, 140, 160, 150, 170, 180, 200, 210, 230, 240, 260)
> Sales_B <- c(190, 210, 130, 250, 240, 180, 170, 180, 200, 220, 230, 250)

> months <- 1:12

> plot(months, Sales_A, type = "o", col = "blue", xlab = "Month", ylab = "Sales", main
= "Monthly Sales of Products A and B")

> lines(months, Sales_B, type = "o", col = "red")

> legend("topleft", legend = c("Sales_A", "Sales_B"), col = c("blue", "red"), lty = 1)

> install.packages("forecast")

> library(forecast)

> ts_Sales_A <- ts(Sales_A, frequency = 12)

> ts_Sales_B <- ts(Sales_B, frequency = 12)

> fit_A <- auto.arima(ts_Sales_A)

> fit_B <- auto.arima(ts_Sales_B)

> forecast_A <- forecast(fit_A, h = 6)

> forecast_B <- forecast(fit_B, h = 6)

> plot(forecast_A, main = "Sales Forecast for Product A", xlab = "Month", ylab =
"Sales")

> plot(forecast_B, main = "Sales Forecast for Product B", xlab = "Month", ylab =
"Sales")

You might also like