poly - Polynomial Regression Stat 420 Dalpiaz It is well...

This preview shows page 1 - 5 out of 22 pages.

Polynomial RegressionStat 420, DalpiazMarch 18, 2015It is well known that the sales response to advertising usually follows a curve reflecting the diminishingreturns to advertising expenditure. As a company increases its advertising expenditure, sales increase, but therate of increase drops continually after a certain point. If we consider company sales profits as a function ofadvertising expenditure, we find that the response function can be very well approximated by a second-order(quadratic) model. For a particular company, the data on monthly salesyand monthly advertising expenditurex, both in hundred thousand dollars, can be found in the data below.sales <-c(5.0,6.0,6.5,7.0,7.5,8.0,10.0,10.8,12.0,13.0,15.5,15.0,16.0,17.0,18.0,18.0,18.5,21.0,20.0,22.0,23.0)advert <-c(1.0,1.8,1.6,1.7,2.0,2.0,2.3,2.8,3.5,3.3,4.8,5.0,7.0,8.1,8.0,10.0,8.0,12.7,12.0,15.0,14.4)marketing <-data.frame(sales,advert)head(marketing)##sales advert## 15.01.0## 26.01.8## 36.51.6## 47.01.7## 57.52.0## 68.02.0plot(marketing$advert,marketing$sales,,xlab ="Advert Spending (in $100,000)",ylab ="Sales (in $100,000)")24681012145101520Advert Spending (in $100,000)Sales (in $100,000)
We want to fit the model,yi=β0+β1xi+β2x2i+iwhereiN(0, σ2)fori= 1,2,· · ·21.Thus, ourXmatrix is,1x1x211x2x221x3x23. . .. . .. . .1x21x221We can then proceed to fit the model as we have in the past for multiple linear regression.ˆβ=XTX-1XTYE[ˆβ] =βV ar[ˆβ] =σ2XTX-1mark_mod <-lm(sales ~ advert,data =marketing)summary(mark_mod)#### Call:## lm(formula = sales ~ advert, data = marketing)#### Residuals:##Min1QMedian3QMax## -2.7845 -1.4762 -0.51031.23613.1869#### Coefficients:##Estimate Std. Error t value Pr(>|t|)## (Intercept)6.59270.70319.377 1.47e-08 ***## advert1.19180.093712.718 9.65e-11 ***## ---## Signif. codes:0***0.001**0.01*0.05.0.11#### Residual standard error: 1.907 on 19 degrees of freedom## Multiple R-squared:0.8949, Adjusted R-squared:0.8894## F-statistic: 161.8 on 1 and 19 DF,p-value: 9.646e-11mark_mod_poly2 <-lm(sales ~ advert +I(advert^2),data =marketing)summary(mark_mod_poly2)#### Call:## lm(formula = sales ~ advert + I(advert^2), data = marketing)#### Residuals:
##Min1QMedian3QMax## -1.9175 -0.8333 -0.19480.92922.1385#### Coefficients:##Estimate Std. Error t value Pr(>|t|)## (Intercept)3.515050.738474.760 0.000157 ***## advert2.514780.257969.749 1.32e-08 ***## I(advert^2) -0.087450.01658-5.275 5.14e-05 ***## ---## Signif. codes:0***0.001**0.01*0.05.0.11#### Residual standard error: 1.228 on 18 degrees of freedom## Multiple R-squared:0.9587, Adjusted R-squared:0.9541## F-statistic:209 on 2 and 18 DF,p-value: 3.486e-13Here we see that with the first order term in the model, the quadratic term is also significant.X <-cbind(rep(1,21), marketing$advert, marketing$advert^2)t(X) %*% X##[,1][,2][,3]## [1,]21.00127.001182.26## [2,]127.001182.2613416.17## [3,] 1182.26 13416.17 166843.66solve(t(X) %*% X) %*%t(X) %*% marketing$sales##[,1]## [1,]3.51504670## [2,]2.51478201## [3,] -0.08745394Here we verify the parameter estimates were found as we would expect.We could also add higher order terms, ourXmatrix simply becomes larger again.yi=β0+β1xi+β2x2i+β3x3i+imark_mod_poly3 <-lm(sales ~ advert +I(advert^2) +I(advert^3),data =marketing)summary(mark_mod_poly3)#### Call:## lm(formula = sales ~ advert + I(advert^2) + I(advert^3), data = marketing)#### Residuals:##Min1QMedian3QMax## -1.44322 -0.61310 -0.015270.681311.22517#### Coefficients:##Estimate Std. Error t value Pr(>|t|)## (Intercept) -0.0558880.909533-0.061 0.951720
## advert4.9593100.5483719.044 6.61e-08 ***## I(advert^2) -0.4696690.082033-5.725 2.48e-05 ***## I(advert^3)0.0161310.0034294.704 0.000205 ***## ---## Signif. codes:0***0.001**0.01*0.05.0.11#### Residual standard error: 0.8329 on 17 degrees of freedom## Multiple R-squared:0.9821, Adjusted R-squared:0.9789

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture