売上データを用いて以下の分析をし、( )内から適切な語句を選ぶ。
① 価格と売上数量の間に相関があるといえるか有意水準5%で検定せよ。
② 売上数量を目的変数、価格、特別陳列、最高気温を説明変数として重回帰分析を行い、各説明変数は目的変数に影響を与えるといえるか有意水準5%で検定せよ。
③ 価格が120円、特別陳列があり、最高気温が30度のときの売上数量の予測値を求めよ。
# 売上データを読み込む
sales <- read.table("sales.txt", header=T)
head(sales)
## date units price disp feat temp
## 1 1 27 130 0 A 24
## 2 2 23 130 0 A 23
## 3 3 41 120 1 A 27
## 4 4 39 120 1 A 26
## 5 5 18 130 0 A 21
## 6 6 24 130 0 A 21
par(family = "HiraginoSans-W3") #日本語が文字化けしないようにおまじない
plot(sales$price, sales$units, xlab = "価格", ylab = "売上")
散布図からは、価格が上がると売上は下がる傾向がありそう。
① 価格と売上数量の間に相関があるといえるか有意水準5%で検定せよ。
price <- sales$price
units <- sales$units
cor.test(price, units)
##
## Pearson's product-moment correlation
##
## data: price and units
## t = -5.3339, df = 26, p-value = 1.395e-05
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.8631496 -0.4789201
## sample estimates:
## cor
## -0.7228437
相関係数の値は-0.723で、\(p\)値はほとんどゼロなので、有意な負の相関があるといえる。
② 売上数量を目的変数、価格、特別陳列、最高気温を説明変数として重回帰分析を行い、各説明変数は目的変数に影響を与えるといえるか有意水準5%で検定せよ。
# ②
model.units <- lm(units ~ price + disp + temp, data=sales)
summary(model.units)
##
## Call:
## lm(formula = units ~ price + disp + temp, data = sales)
##
## Residuals:
## Min 1Q Median 3Q Max
## -7.6810 -2.2590 -0.6408 2.8390 9.3331
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 51.26755 14.46492 3.544 0.00165 **
## price -0.34906 0.09559 -3.652 0.00126 **
## disp 5.85765 1.81381 3.229 0.00358 **
## temp 0.75940 0.21986 3.454 0.00206 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.119 on 24 degrees of freedom
## Multiple R-squared: 0.7416, Adjusted R-squared: 0.7094
## F-statistic: 22.97 on 3 and 24 DF, p-value: 3.109e-07
すべての係数の\(p\)値は1%未満で有意である。
③ 価格が120円、特別陳列があり、最高気温が30度のときの売上数量の予測値を求めよ。
b0 <- model.units$coefficients[[1]]
b1 <- model.units$coefficients[[2]]
b2 <- model.units$coefficients[[3]]
b3 <- model.units$coefficients[[4]]
c(b0,b1,b2,b3)
## [1] 51.2675496 -0.3490616 5.8576485 0.7594023
b0 + b1*120 + b2 + b3*30
## [1] 38.01987