library(readxl)
library(lmtest)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(fastDummies)
## Warning: package 'fastDummies' was built under R version 4.3.2
## Thank you for using fastDummies!
## To acknowledge our work, please cite the package:
## Kaplan, J. & Schlegel, B. (2023). fastDummies: Fast Creation of Dummy (Binary) Columns and Rows from Categorical Variables. Version 1.7.1. URL: https://github.com/jacobkap/fastDummies, https://jacobkap.github.io/fastDummies/.
library(corrplot)
## corrplot 0.92 loaded
library(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
restaurant <- read_excel("restaurant.xlsx")
View(restaurant)
str(restaurant)
## tibble [244 × 7] (S3: tbl_df/tbl/data.frame)
##  $ total_bill: num [1:244] 17 10.3 21 23.7 24.6 ...
##  $ tip       : num [1:244] 1.01 1.66 3.5 3.31 3.61 4.71 2 3.12 1.96 3.23 ...
##  $ gender    : chr [1:244] "Female" "Male" "Male" "Male" ...
##  $ smoker    : chr [1:244] "No" "No" "No" "No" ...
##  $ day       : chr [1:244] "Sun" "Sun" "Sun" "Sun" ...
##  $ time      : chr [1:244] "Dinner" "Dinner" "Dinner" "Dinner" ...
##  $ size      : num [1:244] 2 3 3 2 4 4 2 4 2 2 ...
summary(restaurant)
##    total_bill         tip            gender             smoker         
##  Min.   : 3.07   Min.   : 1.000   Length:244         Length:244        
##  1st Qu.:13.35   1st Qu.: 2.000   Class :character   Class :character  
##  Median :17.80   Median : 2.900   Mode  :character   Mode  :character  
##  Mean   :19.79   Mean   : 2.998                                        
##  3rd Qu.:24.13   3rd Qu.: 3.562                                        
##  Max.   :50.81   Max.   :10.000                                        
##      day                time                size     
##  Length:244         Length:244         Min.   :1.00  
##  Class :character   Class :character   1st Qu.:2.00  
##  Mode  :character   Mode  :character   Median :2.00  
##                                        Mean   :2.57  
##                                        3rd Qu.:3.00  
##                                        Max.   :6.00
restaurant<-dummy_cols(restaurant,select_columns = "gender")
restaurant<-dummy_cols(restaurant,select_columns = "smoker")
restaurant<-dummy_cols(restaurant,select_columns = "time")
str(restaurant)
## tibble [244 × 13] (S3: tbl_df/tbl/data.frame)
##  $ total_bill   : num [1:244] 17 10.3 21 23.7 24.6 ...
##  $ tip          : num [1:244] 1.01 1.66 3.5 3.31 3.61 4.71 2 3.12 1.96 3.23 ...
##  $ gender       : chr [1:244] "Female" "Male" "Male" "Male" ...
##  $ smoker       : chr [1:244] "No" "No" "No" "No" ...
##  $ day          : chr [1:244] "Sun" "Sun" "Sun" "Sun" ...
##  $ time         : chr [1:244] "Dinner" "Dinner" "Dinner" "Dinner" ...
##  $ size         : num [1:244] 2 3 3 2 4 4 2 4 2 2 ...
##  $ gender_Female: int [1:244] 1 0 0 0 1 0 0 0 0 0 ...
##  $ gender_Male  : int [1:244] 0 1 1 1 0 1 1 1 1 1 ...
##  $ smoker_No    : int [1:244] 1 1 1 1 1 1 1 1 1 1 ...
##  $ smoker_Yes   : int [1:244] 0 0 0 0 0 0 0 0 0 0 ...
##  $ time_Dinner  : int [1:244] 1 1 1 1 1 1 1 1 1 1 ...
##  $ time_Lunch   : int [1:244] 0 0 0 0 0 0 0 0 0 0 ...
##  - attr(*, ".internal.selfref")=<externalptr>
result<-lm(tip~gender_Female,data = restaurant)
summary(result)
## 
## Call:
## lm(formula = tip ~ gender_Female, data = restaurant)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.0896 -1.0896 -0.0896  0.6666  6.9104 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     3.0896     0.1102  28.032   <2e-16 ***
## gender_Female  -0.2562     0.1846  -1.388    0.166    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.381 on 242 degrees of freedom
## Multiple R-squared:  0.007896,   Adjusted R-squared:  0.003797 
## F-statistic: 1.926 on 1 and 242 DF,  p-value: 0.1665
result2<-lm(tip~gender_Male+smoker_No+time_Dinner+total_bill,data = restaurant)
summary(result2)
## 
## Call:
## lm(formula = tip ~ gender_Male + smoker_No + time_Dinner + total_bill, 
##     data = restaurant)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.1084 -0.5883 -0.0865  0.4979  3.8175 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.825152   0.211739   3.897 0.000126 ***
## gender_Male -0.029049   0.140982  -0.206 0.836931    
## smoker_No    0.149405   0.135841   1.100 0.272503    
## time_Dinner  0.005583   0.151701   0.037 0.970671    
## total_bill   0.105900   0.007589  13.954  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.026 on 239 degrees of freedom
## Multiple R-squared:  0.4594, Adjusted R-squared:  0.4504 
## F-statistic: 50.78 on 4 and 239 DF,  p-value: < 2.2e-16
b<-cor(restaurant[c("gender_Male","smoker_No","time_Dinner","total_bill")])
b
##              gender_Male    smoker_No time_Dinner  total_bill
## gender_Male  1.000000000 -0.002815952   0.2052313  0.14487734
## smoker_No   -0.002815952  1.000000000  -0.0549211 -0.08572126
## time_Dinner  0.205231296 -0.054921104   1.0000000  0.18311761
## total_bill   0.144877337 -0.085721257   0.1831176  1.00000000
corrplot(b)

stargazer(data=result2,type="text",title = "PARIRESULT",digits = 2,out = "table.text")
## 
## PARIRESULT
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                                 tip            
## -----------------------------------------------
## gender_Male                    -0.03           
##                               (0.14)           
##                                                
## smoker_No                      0.15            
##                               (0.14)           
##                                                
## time_Dinner                    0.01            
##                               (0.15)           
##                                                
## total_bill                    0.11***          
##                               (0.01)           
##                                                
## Constant                      0.83***          
##                               (0.21)           
##                                                
## -----------------------------------------------
## Observations                    244            
## R2                             0.46            
## Adjusted R2                    0.45            
## Residual Std. Error       1.03 (df = 239)      
## F Statistic           50.78*** (df = 4; 239)   
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01