Analyze the relationship between a company's advertising expenditure, its product price, future value, tax, interest rate, and its sales revenue.

Create a Hypothetical Data with 5 variables

set.seed(100)

expenditure = round(rnorm(10006, 5000, 1000), 2)
product_price = round(rnorm(10006, 250000, 40000), 2)
interest_rate = round(rnorm(10006, 0.07, 0.02),2)
future_value = round((product_price * (1+interest_rate)), 2)
tax <- ifelse( product_price > 300000, 0.05, 0.03)


datab = data.frame(expenditure, product_price, future_value, tax, interest_rate)
head(datab)
##   expenditure product_price future_value  tax interest_rate
## 1     4497.81      218590.2     222962.0 0.03          0.02
## 2     5131.53      285034.1     302136.2 0.03          0.06
## 3     4921.08      244133.2     270987.8 0.03          0.11
## 4     5886.78      263328.1     289660.9 0.03          0.10
## 5     5116.97      329340.7     355688.0 0.05          0.08
## 6     5318.63      278004.0     303024.3 0.03          0.09

Penjelasan Variabel :
Expendiiture : Pengeluaran untuk iklan oleh developer dalam USD
Product Price : Harga Properti dalam USD
Future Value : Nilai Properti diprojeksikan 3 tahun ke depan dalam USD
Tax : Rate persen pajak berdasarkan harga properti
Interest Rate : Persen pertumbuhan properti

Create Sales Revenue Variables

set.seed(123)
datab$sales_revenue = round((rnorm(10006, 0.04, 0.005) * datab$product_price) , 2)
head(datab)
##   expenditure product_price future_value  tax interest_rate sales_revenue
## 1     4497.81      218590.2     222962.0 0.03          0.02       8131.04
## 2     5131.53      285034.1     302136.2 0.03          0.06      11073.32
## 3     4921.08      244133.2     270987.8 0.03          0.11      11667.99
## 4     5886.78      263328.1     289660.9 0.03          0.10      10625.96
## 5     5116.97      329340.7     355688.0 0.05          0.08      13386.53
## 6     5318.63      278004.0     303024.3 0.03          0.09      13504.13

Sales Revenue dihitung berdasarkan persenan dari harga properti.

Regression Models

Pembuatan Model regresi dimulai dari mengecek korelasi antar variabel untuk kemudian dimasukkan ke Model Linear.

library(corrplot)
## corrplot 0.92 loaded
corrplot(cor(datab), method = 'number')

Dari Hasil Corrplot diatas, didapatkan semua variabel memiliki pengaruh yang cukup signifikan terhadap satu sama lain. Bahkan future value dengan profuct price memiliki korelas 100%

model_a = lm(sales_revenue ~ expenditure + product_price + future_value + tax + interest_rate , datab)
summary(model_a)
## 
## Call:
## lm(formula = sales_revenue ~ expenditure + product_price + future_value + 
##     tax + interest_rate, data = datab)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5288.1  -814.1   -10.6   830.0  5371.8 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)
## (Intercept)    3.461e+02  2.912e+02   1.188    0.235
## expenditure    9.696e-03  1.270e-02   0.763    0.445
## product_price  1.727e-02  1.641e-02   1.052    0.293
## future_value   2.105e-02  1.534e-02   1.372    0.170
## tax            8.234e+02  2.594e+03   0.317    0.751
## interest_rate -5.323e+03  3.880e+03  -1.372    0.170
## 
## Residual standard error: 1263 on 10000 degrees of freedom
## Multiple R-squared:  0.6141, Adjusted R-squared:  0.6139 
## F-statistic:  3183 on 5 and 10000 DF,  p-value: < 2.2e-16

Berdasarkan summary model Linear diatas, didapatkan model Linear dengan nilai prediksi hampir 61%. dengan model

\[ 346,059 + 0,0096*Expenditure + 0.017 * Product Price + 0.021 * Future Value + 823.36 * Tax - 5322,88 * Interest Rate \]

Semua varibael independen dapat menjelaskankan variabel dependen sebesar 61%, angka tersebut dapat ditingkatkan denganb mengurngi variabel yang tidak memiliki korelasi signfikan.

Plot

plot(model_a, which = 1)

Berdasarkan plot diatas, residual bersifat homogen kepada garis linear model regresi sehingga kesalahan atau error rate relatif konstan sepanjang dataset.

Investigate the factors influencing housing prices as the following instructions:

Hypothetical Dataset

set.seed(144)

house_size <- round(rnorm(20006, 220, 45), 2)
bedrooms <- ifelse(house_size >= 230, sample(6:8, 20007, replace = T), ifelse(house_size >= 120, sample(3:5, 20007, replace = T), sample(1:2, 20007, replace = T)))
city <- sample( 1:5 , 20006, replace = TRUE)
toll_access <- sample(c(0:1), 20006, replace = TRUE)
house_age <- sample(0:10, 20006, replace = TRUE)
price <- round(rnorm(20006, mean=200, sd=30) * house_size + 
               rnorm(20006, mean=50, sd=6) * bedrooms - 
               rnorm(20006, mean=60, sd=10) * house_age + 
               ifelse(toll_access == 1, 300, 0) + 
               ifelse(city == "1", 900, 
                      ifelse(city == "2", 680, 
                             ifelse(city == "3", 640.5, 
                                    ifelse(city == "4", 525, 580.5 )))),2)


# Create data frame
data10 <- data.frame(house_size, bedrooms, city, toll_access, house_age,price)

data10$bedrooms = as.numeric(data10$bedrooms)
head(data10)
##   house_size bedrooms city toll_access house_age    price
## 1     145.72        3    3           1         1 34871.49
## 2     247.13        6    4           0         3 59051.60
## 3     198.68        4    2           0        10 41297.34
## 4     139.11        4    4           1         4 26038.87
## 5     156.05        5    5           1         5 27725.53
## 6     227.15        4    3           0         6 46650.77

Keterangan Variabel
1. House Size = Luas Bangunan dalam Meter Persegi setiap kenaikan 1 meter persegi menaikan harga rumah kurang lebih 100-200 USD
2. Bedrooms = Jumlah Kamar Tidur yangbterbagi berdasarkan Luas Bangunan mempengaruhi kenaikan sebesar 50-100 USD
3. City = Kota tempat properti tersebut yang mana mempengaruhi harga properti. Menaikkan harga basic properti.
1 = “Jakarta”, 2 = “Tangerang Selatan”, 3 = “Tangerang Kota”, 4 = “Bogor”, 5 = “Bekasi”)
4. Toll Access = Perumahan atau Cluster dengan Akses Toll langsung mempengaruhi kenaikan harga properti
5. House_Age = Harga rumah mempengaruhi depresiasi harga bangunan.

Regression Model

Pertama, dilakukan tes korelasi untuk mengetahui prediktor mana yang paling kuat.

library(corrplot)
corrplot(cor(data10), method = 'number')

Dilihat bahwa prediktor paling kuat dalam Harga Properti yaitu Luas Bangunan dan Jumlah Kamar Tidur.

model10 = lm(price ~ house_size  + bedrooms +  city +  toll_access +  house_age , data10)
summary(model10)
## 
## Call:
## lm(formula = price ~ house_size + bedrooms + city + toll_access + 
##     house_age, data = data10)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -29660.0  -4290.9     43.2   4316.7  28891.6 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  991.547    274.815   3.608 0.000309 ***
## house_size   197.746      1.527 129.477  < 2e-16 ***
## bedrooms     125.450     39.639   3.165 0.001554 ** 
## city         -68.969     33.441  -2.062 0.039184 *  
## toll_access  332.385     94.601   3.514 0.000443 ***
## house_age    -65.505     14.966  -4.377 1.21e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6689 on 20000 degrees of freedom
## Multiple R-squared:  0.6466, Adjusted R-squared:  0.6465 
## F-statistic:  7318 on 5 and 20000 DF,  p-value: < 2.2e-16

Persamaan FUngsi dari model regresinya adalah

\[ 991,547 + 197,746 * House_Size + 125,45 * Bedrooms - 68,969 * City + 332.38 * Toll Access - 65.5 * House_Age \]

Dengan Nilai R-Squared sebesar 64,6% yang berarti variabel dependen tersebut dapat dijelaskab dengan lumayan signifikan oleh Variabel independen tersebut.

Mengganti City dan Toll sebagai factor

data100 = data10
data100$city = as.factor(data100$city)
data100$toll_access = as.factor(data100$toll_access)

head(data100)
##   house_size bedrooms city toll_access house_age    price
## 1     145.72        3    3           1         1 34871.49
## 2     247.13        6    4           0         3 59051.60
## 3     198.68        4    2           0        10 41297.34
## 4     139.11        4    4           1         4 26038.87
## 5     156.05        5    5           1         5 27725.53
## 6     227.15        4    3           0         6 46650.77

Linear Models with factor

model100 = lm(price ~ house_size  + bedrooms +  city +  toll_access +  house_age , data100)
summary(model100)
## 
## Call:
## lm(formula = price ~ house_size + bedrooms + city + toll_access + 
##     house_age, data = data100)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -29717.0  -4267.9     41.7   4331.2  28982.0 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1096.535    272.138   4.029 5.61e-05 ***
## house_size    197.688      1.527 129.447  < 2e-16 ***
## bedrooms      128.192     39.643   3.234 0.001224 ** 
## city2        -490.598    150.523  -3.259 0.001119 ** 
## city3        -253.007    149.894  -1.688 0.091445 .  
## city4        -472.346    149.479  -3.160 0.001580 ** 
## city5        -354.464    149.473  -2.371 0.017729 *  
## toll_access1  331.209     94.587   3.502 0.000463 ***
## house_age     -65.313     14.964  -4.365 1.28e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6688 on 19997 degrees of freedom
## Multiple R-squared:  0.6467, Adjusted R-squared:  0.6466 
## F-statistic:  4576 on 8 and 19997 DF,  p-value: < 2.2e-16

Dari Model yang didapatkan di atas di intepretasikan bahwa

\[ 1096,53 + 197,68 * House_Size + 128,19 * Bedrooms + 331.2.8 * Toll Access - 65.31 * HouseAge - c * City \] Dengan nilai p-value < 0.05 maka bisa dipastikan bahwa model Regresi yang kita buat memiliki salah satu variabel independen yang cukup signifikan dalam menggambarkan variabel dependen. Dengan nilai R-Squared 64,66%. Serta pada T-statistics yang lebih kecil dari 0,05 menunjukkan bahwa variabel tersebut memiliki hubungan yang signifikan dalam menggambarkan Variabel dependen seperti yang digambarkan pada Tabel Summary yaitu kolom Pr(>t)

Nilai VIF

library(car)
## Loading required package: carData
vif(model10)
##  house_size    bedrooms        city toll_access   house_age 
##    2.103794    2.104216    1.000622    1.000377    1.000670
vif(model100)
##                 GVIF Df GVIF^(1/(2*Df))
## house_size  2.104251  1        1.450604
## bedrooms    2.105314  1        1.450970
## city        1.001477  4        1.000184
## toll_access 1.000439  1        1.000219
## house_age   1.000777  1        1.000388

Dari 2 model yang telah dibuat, dimana yang satu menggunakan semua numerik dan satunya terdapat nilai faktor semuanya memiliki nilai VIF lebih kecil dari 5 yang artinya tidak terdapat multikolinearitas antar avariabel independen.

Breusch Pagan Test

library(lmtest)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
bptest(model10)
## 
##  studentized Breusch-Pagan test
## 
## data:  model10
## BP = 1232.1, df = 5, p-value < 2.2e-16
bptest(model100)
## 
##  studentized Breusch-Pagan test
## 
## data:  model100
## BP = 1233.1, df = 8, p-value < 2.2e-16

Dari hasil keduanya, Breush Pagan Test memiliki nilai p-value < 0.05 sehingga bisa dikatakan ada heteroskedikitas pada model linear

Rainbow Test

raintest(model10)
## 
##  Rainbow test
## 
## data:  model10
## Rain = 0.99524, df1 = 10003, df2 = 9997, p-value = 0.5943
raintest(model100)
## 
##  Rainbow test
## 
## data:  model100
## Rain = 0.99459, df1 = 10003, df2 = 9994, p-value = 0.6068

Karena P-Value keduanya > 0.05 Maka dapat dikatakan bahwa Antara variabel memiliki hubungan linear yang signifikan.

Plot

par(mfrow= c(2,2))

plot(model10, which = 1)
plot(model10, which = 2)
plot(model10, which = 3)
plot(model10, which = 4)

par(mfrow= c(2,2))

plot(model100, which = 1)
plot(model100, which = 2)
plot(model100, which = 3)
plot(model100, which = 4)

Plot Residual Menunjukkan hubungan linear antara residu dan nilai yang linear.
Plot residual Q-Q yang mennunjukkan distribusi normal.
Plot Scale-Location yang menunjukkan Homogentitas.
Plot Cooks Distance yang menunjukkan bagwa hanya diytemukan 3 outliers pada dataset.