RDataRegression - R Regression Analysis Xinhui Zhang 2013...

Info icon This preview shows pages 1–5. Sign up to view the full content.

R Regression Analysis Xinhui Zhang 2013 Edelman Laureate Professor Wright State University October 2, 2016 A majority of the materials are taken from the following book: ”An Introduction to Statistical Learning with Applications in R” by Gareth James, Daniela Witten, Trevor Hastie and Robert Tibshirani. The book can be downloaded at ~ gareth/ISL/index.html To start, we clean the R workspace and release any memory not in use. ################################################################################ # Clean the objects in the enviroment and gabarage collection of memory ################################################################################ rm ( list = ls ()) gc () ## used (Mb) gc trigger (Mb) max used (Mb) ## Ncells 303249 16.2 592000 31.7 369318 19.8 ## Vcells 514313 4.0 1023718 7.9 786425 6.0 1 Linear Regression linear regression is a very simple approach for supervised learning. In particular, linear regression is a useful tool for predicting a quantitative response. The data used in the illustraction is an advertising data which displays sales (in thousands of units) for a particular product as a function of advertising budgets (in thousands of dollars) for TV, radio,and newspapermedia. 1
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

advertising <- read.csv ( "Advertising.csv" , header = TRUE ) str (advertising) ## 'data.frame': 200 obs. of 4 variables: ## $ TV : num 230.1 44.5 17.2 151.5 180.8 ... ## $ Radio : num 37.8 39.3 45.9 41.3 10.8 48.9 32.8 19.6 2.1 2.6 ... ## $ Newspaper: num 69.2 45.1 69.3 58.5 58.4 75 23.5 11.6 1 21.2 ... ## $ Sales : num 22.1 10.4 9.3 18.5 12.9 7.2 11.8 13.2 4.8 10.6 ... Question: Suppose that in our role as consultants we are asked to suggest, on the basis of this data, a marketing plan for next year that will result in high product sales. What information would be useful in order to provide such a recommendation? Here are a few important questions that we might seek to address: 1. Is there a relationship between advertising budget and sales? 2. How strong is the relationship between advertising budget and sales? 3. Which media contribute to sales? 4. How accurately can we estimate the effect of each medium on sales? 5. Is the relationship linear? 6. Is there synergy among the advertising media? 1.1 Simple Linear Regression: Simple Linear Regression approximates a relationship between variables X and Y and can be written as Y β 0 + β 1 × X The determination of the parameters beta 0 and β 1 can be done through optimization. In r, the command to do a simple linear equation is the lm commend as follows. attach (advertising) ; #pairs(advertising) salesLM <- lm (Sales ~ TV, data = advertising); summary (salesLM) ## ## Call: ## lm(formula = Sales ~ TV, data = advertising) 2
Image of page 2
## ## Residuals: ## Min 1Q Median 3Q Max ## -8.3860 -1.9545 -0.1913 2.0671 7.2124 ## ## Coefficients: ## Estimate Std. Error t value Pr(>|t|) ## (Intercept) 7.032594 0.457843 15.36 <2e-16 *** ## TV 0.047537 0.002691 17.67 <2e-16 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## ## Residual standard error: 3.259 on 198 degrees of freedom ## Multiple R-squared: 0.6119,Adjusted R-squared: 0.6099 ## F-statistic: 312.1 on 1 and 198 DF, p-value: < 2.2e-16 plot (TV, Sales ); abline (salesLM, col = "red" ) 0 50 100 150 200 250 300 5 10 15 20 25 TV Sales 3
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

1.2 Parameter Results and Residuals: The parameters estimated are obtained through the lm are β 0 = 7 . 03 and β 1 = 0 . 047. In other words, according to this approximation, an additional $1,000 spent on TV advertising is associated with selling approximately 47.5 additional units of the product.
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern