library(readxl)
marketing <- read_excel("marketing.xlsx")
## New names:
## • `` -> `...2`
## • `` -> `...3`
## • `` -> `...4`
## • `` -> `...5`
library(car)
## Loading required package: carData
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ✖ dplyr::recode() masks car::recode()
## ✖ purrr::some()   masks car::some()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(corrplot) 
## corrplot 0.92 loaded
library(psych)
## 
## Attaching package: 'psych'
## 
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
## 
## The following object is masked from 'package:car':
## 
##     logit
require(stargazer)
## Loading required package: stargazer
## 
## Please cite as: 
## 
##  Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
##  R package version 5.2.3. https://CRAN.R-project.org/package=stargazer

1 Mô tả dữ liệu

Tập tin marketing.xlsx dùng để phân tích ảnh hưởng của các hình thức quảng cáo lên doanh thu. Dữ liệu bao gồm 4 biến:

  • youtube, facebook và newwspaper là số tiền chi cho quảng cáo (đơn vị: triệu đồng).

  • sales là biến doanh thu. Bộ số liệu có 200 quan sát, thu nhập tại 200 cửa hàng.

marketing <- read_excel("marketing.xlsx")
## New names:
## • `` -> `...2`
## • `` -> `...3`
## • `` -> `...4`
## • `` -> `...5`
head(marketing)
## # A tibble: 6 × 5
##   marketing ...2    ...3     ...4      ...5     
##       <dbl> <chr>   <chr>    <chr>     <chr>    
## 1        NA youtube facebook newspaper sales    
## 2         1 200.92  142.17   145.41    943.0419 
## 3         2 156.26  129.85   62.7      856.2597 
## 4         3 124.38  187.57   140.04    964.9689 
## 5         4 157.69  187.48   143.94    1017.4412
## 6         5 158.23  222.41   116.04    1115.299
str(marketing)
## tibble [201 × 5] (S3: tbl_df/tbl/data.frame)
##  $ marketing: num [1:201] NA 1 2 3 4 5 6 7 8 9 ...
##  $ ...2     : chr [1:201] "youtube" "200.92" "156.26" "124.38" ...
##  $ ...3     : chr [1:201] "facebook" "142.17" "129.85" "187.57" ...
##  $ ...4     : chr [1:201] "newspaper" "145.41" "62.7" "140.04" ...
##  $ ...5     : chr [1:201] "sales" "943.0419" "856.2597" "964.9689" ...

2 Chạy hồi qui

Mô hình hồi quy bội có dạng:

Y=β1+β2X2+β3X3+..+βkXk+u

Xây dựng mô hình hồi quy bội (multiple regression) để phân tích tác động của các hình thức quảng cáo lên doanh thu và diễn giải kết quả. cụ thể:

  • Biến phụ thuộc: doanh thu sales.

  • Biến độc lập: youtube,facebook,newspaper lần lượt là số tiền chi cho quảng cáo trên Youtube, Facebook và trên báo chí.

2.1 Ước lượng mô hình

# Sử dụng lệnh lm()

2.2 R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

2.3 Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.