Sie sind auf Seite 1von 4

Name: Sumeet Karbhari

Reg No: 18BCE7062

Q1. Study the relationship between the monthly e-


commerce sales and the online advertising costs. You
have the survey results for 7 online stores for the last
year task is to find the equation of the straight line that
fits the data best.

> ## x = commerce_sales
> ## y = online_advertising
> x = c(368,340,665,954,331,556,376)
> y = c(1.7,1.5,2.8,5,1.3,2.2,1.3
+ y = c(1.7,1.5,2.8,5,1.3,2.2,1.3)
Error: unexpected symbol in:
"y = c(1.7,1.5,2.8,5,1.3,2.2,1.3
y"
> y = c(1.7,1.5,2.8,5,1.3,2.2,1.3)
> relation = lm(x~y)
> relation

Call:
lm(formula = x ~ y)

Coefficients:
(Intercept) y
125.8 171.5

> summary(relation)

Call:
lm(formula = x ~ y)

Residuals:
1 2 3 4 5 6 7
-49.33 -43.03 59.06 -29.16 -17.74 52.94 27.26

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 125.83 39.55 3.182 0.024484 *
y 171.47 15.39 11.139 0.000102 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 49.97 on 5 degrees of freedom


Multiple R-squared: 0.9613, Adjusted R-squared: 0.9535
F-statistic: 124.1 on 1 and 5 DF, p-value: 0.0001017

> a = data.frame(x,y)
>a
x y
1 368 1.7
2 340 1.5
3 665 2.8
4 954 5.0
5 331 1.3
6 556 2.2
7 376 1.3
> s = data.frame(y = 5)
> result = predict(relation,y)
Error in eval(predvars, data, env) :
numeric 'envir' arg not of length one
> result = predict(relation,s)
> result
1
983.1627
> s = data.frame(y = 6)
> result = predict(relation,s)
> result
1
1154.628
> ## graph plot
>
> plot(y,x,col ="black" , main ="x and y regression" , abline(relation) , xlab =
"online_advertising" , ylab = "commerce_sales")

Das könnte Ihnen auch gefallen