Você está na página 1de 2

R Code Used:

#Loading Dataset (*combined is the .csv file name)


>combined <- read.csv(file.choose(), header=T)
>combined
#swift
>swift <- read.csv(file.choose(),header=T)
>swift
#alto
>alto <- read.csv(file.choose(),header=T)
>alto
#i20
> i20 <- read.csv(file.choose(),header=T)
> i20
#Summary of dataset
>summary(combined)
#Finding correlation between independent variables
> cor(combined)
#Scatter plot
> plot(combined)
# Linear Modelling (combined)
> model1 <- lm(UnitSales~AvgPetrolPrice+IntRates+Price,combined)
> summary(model1)
> model2 <- lm(UnitSales~AvgPetrolPrice+IntRates+Price+GDPPPP, combined)
> summary(model2)
> model3 <- lm(UnitSales~AvgPetrolPrice+IntRates+Price+GDPPPP+Inf. , combined)
> summary(model3)
# Linear Modelling for individual car models
# Swift
> swmodel1 <- lm(SwUnitSales~AvgPetPrice+IntRates+Price, swift)
> summary(swmodel1)
> swmodel2 <- lm(SwUnitSales~AvgPetPrice+IntRates+Price+GDPPPP, swift)
> summary(swmodel2)
> swmodel3 <- lm(SwUnitSales~AvgPetPrice+IntRates+Price+GDPPPP+Inf. , swift)
> summary(swmodel3)
# Alto
> Almodel1 <- lm(AltoUnitSales~AvgPetrolPrice+Int+Price, alto)
> summary(Almodel1)
> Almodel2 <- lm(AltoUnitSales~AvgPetrolPrice+Int+Price+GDPPPP, alto)
> Summary(Almodel2)
> Almodel3 <- lm(AltoUnitSales~AvgPetrolPrice+Int+Price+GDPPPP+Inf.,alto)
> summary(Almodel3)
#i20
> i20model1 <- lm(i20unitsales~Avgpetrolprice+Interestrates+Price, i20)
> summary(i20model1)
> i20model2 <- lm(i20unitsales~Avgpetrolprice+Interestrates+Price+GDPPPP, i20)
> summary(i20model2)
> i20model3 <- lm(i20unitsales~Avgpetrolprice+Interestrates+Price+GDPPPP+Inf., i20)
> summary(i20model3)
# Non-Linear Modelling (combined)
> model1<- lm(log(UnitSales)~AvgPetrolPrice+IntRates+Price,AB)
> summary(model1)
> model2<- lm(log(UnitSales)~AvgPetrolPrice+IntRates+Price+GDPPPP,AB)
> summary(model2)
> model3<- lm(log(UnitSales)~AvgPetrolPrice+IntRates+Price+GDPPPP+Inf.,AB)
> summary(model3)
# Heteroskedasticity Analysis (White test)
>library(vars)
>library(het.test)
>dataset <- data.frame(x=combined$AvgPetPrice, y=combined$UnitSales)
>wtest1 <- VAR(dataset, p = 1)
>whites.htest(wtest1)
>dataset <- data.frame(x=combined$IntRates, y=combined$UnitSales)
>wtest2 <- VAR(dataset, p = 1)
>whites.htest(wtest2)
>dataset <- data.frame(x=combined$Price, y=combined$UnitSales)
>wtest3 <- VAR(dataset, p = 1)
>whites.htest(wtest3)
>dataset <- data.frame(x=combined$GDPPPP, y=combined$UnitSales)
>wtest4 <- VAR(dataset, p = 1)
>whites.htest(wtest4)
>dataset <- data.frame(x=combined$Inf., y=combined$UnitSales)
>wtest5 <- VAR(dataset, p = 1)
>whites.htest(wtest5)
#For VIF, Heteroskedastic robust SE
library(car)
library(lmtest)
library(sandwich)

vif(*insert model name*)


coeftest(*insert model name*,vcov=NeweyWest) - Autocorrelation and heterosked robust SE'
coeftest(model1,vcovHC(model1,type="HC1")) - Heterosked robust SE (White standard
error)