Data calling

setwd("/Users/subasishdas1/Desktop/MacPro_File/")
data<-read.csv(file="FFV_counts.csv",head=TRUE,sep=",")
names(data)
##  [1] "year"                                      
##  [2] "article_id"                                
##  [3] "state"                                     
##  [4] "Population"                                
##  [5] "Economy"                                   
##  [6] "Car.Ownership"                             
##  [7] "Truck.Ownership"                           
##  [8] "Gasoline.Prices"                           
##  [9] "Gas_lag"                                   
## [10] "Legitimation"                              
## [11] "Entrepreneurial.Experimentation"           
## [12] "Resource.Mobilization"                     
## [13] "Knowledge.development.and.diffusion"       
## [14] "Know_lag"                                  
## [15] "Development.of.Positive.External.Economies"
## [16] "Market.Formation"                          
## [17] "Influence.the.Direction.of.Search"         
## [18] "Abbrev"                                    
## [19] "FFV.Count"                                 
## [20] "MY"                                        
## [21] "EthCons"                                   
## [22] "EthCons_bbl"                               
## [23] "EthProd"                                   
## [24] "FFVStations"                               
## [25] "CumStations"                               
## [26] "RFS"                                       
## [27] "AFV.Manufacturer.Retrofitter"              
## [28] "Acquisition...Fuel.Use"                    
## [29] "Aftermarket.Conversions"                   
## [30] "Air.Quality...Emissions"                   
## [31] "Alternative.Fuel.Dealer"                   
## [32] "Alternative.Fuel.Producer"                 
## [33] "Alternative.Fuel.Purchaser"                
## [34] "Climate.Change...Energy.Initiatives"       
## [35] "Driving...Idling"                          
## [36] "Ethanol"                                   
## [37] "Exemptions"                                
## [38] "Fleet.Purchaser.Manager"                   
## [39] "Fuel.Economy...Efficiency"                 
## [40] "Fuel.Production...Quality"                 
## [41] "Fuel.Taxes"                                
## [42] "Fueling...TSE.Infrastructure.Owner"        
## [43] "Grants"                                    
## [44] "Idle.Reduction"                            
## [45] "Loans.and.Leases"                          
## [46] "Rebates"                                   
## [47] "Registration...Licensing"                  
## [48] "Renewable.Fuel.Standard...Mandate"         
## [49] "Tax.Incentives"                            
## [50] "Vehicle.Owner.Driver"                      
## [51] "Time"                                      
## [52] "Time2"

Count data modeling

F1<-glm(Legitimation~AFV.Manufacturer.Retrofitter+
          Acquisition...Fuel.Use+
          Aftermarket.Conversions+
          Air.Quality...Emissions+
          Alternative.Fuel.Dealer+
          Alternative.Fuel.Producer+
          Alternative.Fuel.Purchaser+
          Climate.Change...Energy.Initiatives+
          Exemptions+Fleet.Purchaser.Manager+
          Fuel.Economy...Efficiency+
          Fuel.Production...Quality+
          Fuel.Taxes+
          Fueling...TSE.Infrastructure.Owner+
          Grants+Idle.Reduction+Loans.and.Leases+
          Rebates+Registration...Licensing+
          Renewable.Fuel.Standard...Mandate+
          Tax.Incentives+Vehicle.Owner.Driver+
          Car.Ownership,
          data=data,family=quasipoisson)
summary(F1)
## 
## Call:
## glm(formula = Legitimation ~ AFV.Manufacturer.Retrofitter + Acquisition...Fuel.Use + 
##     Aftermarket.Conversions + Air.Quality...Emissions + Alternative.Fuel.Dealer + 
##     Alternative.Fuel.Producer + Alternative.Fuel.Purchaser + 
##     Climate.Change...Energy.Initiatives + Exemptions + Fleet.Purchaser.Manager + 
##     Fuel.Economy...Efficiency + Fuel.Production...Quality + Fuel.Taxes + 
##     Fueling...TSE.Infrastructure.Owner + Grants + Idle.Reduction + 
##     Loans.and.Leases + Rebates + Registration...Licensing + Renewable.Fuel.Standard...Mandate + 
##     Tax.Incentives + Vehicle.Owner.Driver + Car.Ownership, family = quasipoisson, 
##     data = data)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -51.115  -14.955   -9.810    1.134  128.190  
## 
## Coefficients:
##                                       Estimate Std. Error t value Pr(>|t|)
## (Intercept)                          4.9459327  0.0919407  53.795  < 2e-16
## AFV.Manufacturer.Retrofitter        -0.1929479  0.1720954  -1.121 0.262536
## Acquisition...Fuel.Use              -0.0732242  0.1893404  -0.387 0.699052
## Aftermarket.Conversions              0.2341197  0.1537874   1.522 0.128294
## Air.Quality...Emissions              0.6258295  0.1962909   3.188 0.001484
## Alternative.Fuel.Dealer              0.2183758  0.1871896   1.167 0.243701
## Alternative.Fuel.Producer           -0.0943103  0.1677529  -0.562 0.574131
## Alternative.Fuel.Purchaser          -0.2736143  0.1577009  -1.735 0.083103
## Climate.Change...Energy.Initiatives  1.0149581  0.2273686   4.464 9.14e-06
## Exemptions                           0.5470088  0.1946693   2.810 0.005070
## Fleet.Purchaser.Manager              0.2441055  0.1919823   1.271 0.203902
## Fuel.Economy...Efficiency            0.2272381  0.1818774   1.249 0.211865
## Fuel.Production...Quality            0.4158005  0.1515572   2.744 0.006207
## Fuel.Taxes                           0.5557059  0.1434652   3.873 0.000116
## Fueling...TSE.Infrastructure.Owner  -0.1849631  0.1910904  -0.968 0.333354
## Grants                               0.1731920  0.1578056   1.098 0.272735
## Idle.Reduction                       0.2185462  0.1892679   1.155 0.248544
## Loans.and.Leases                     0.3964675  0.2246765   1.765 0.077991
## Rebates                             -0.4405115  0.2274441  -1.937 0.053105
## Registration...Licensing             0.1446801  0.1525032   0.949 0.343044
## Renewable.Fuel.Standard...Mandate    0.4887929  0.1938588   2.521 0.011873
## Tax.Incentives                      -0.1870854  0.1781714  -1.050 0.294005
## Vehicle.Owner.Driver                 0.5461028  0.1612267   3.387 0.000739
## Car.Ownership                        0.0002742  0.0002000   1.371 0.170798
##                                        
## (Intercept)                         ***
## AFV.Manufacturer.Retrofitter           
## Acquisition...Fuel.Use                 
## Aftermarket.Conversions                
## Air.Quality...Emissions             ** 
## Alternative.Fuel.Dealer                
## Alternative.Fuel.Producer              
## Alternative.Fuel.Purchaser          .  
## Climate.Change...Energy.Initiatives ***
## Exemptions                          ** 
## Fleet.Purchaser.Manager                
## Fuel.Economy...Efficiency              
## Fuel.Production...Quality           ** 
## Fuel.Taxes                          ***
## Fueling...TSE.Infrastructure.Owner     
## Grants                                 
## Idle.Reduction                         
## Loans.and.Leases                    .  
## Rebates                             .  
## Registration...Licensing               
## Renewable.Fuel.Standard...Mandate   *  
## Tax.Incentives                         
## Vehicle.Owner.Driver                ***
## Car.Ownership                          
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for quasipoisson family taken to be 681.9619)
## 
##     Null deviance: 518436  on 866  degrees of freedom
## Residual deviance: 326468  on 843  degrees of freedom
##   (51 observations deleted due to missingness)
## AIC: NA
## 
## Number of Fisher Scoring iterations: 6
plot(F1)

Correlation plot

#setwd("/Users/subasishdas1/Desktop/MacPro_File/")
#data<-read.csv(file="FFV_counts.csv",head=TRUE,sep=",")
data3 <- data[c(10, 27: 34, 37: 50, 6)]
names(data3)
##  [1] "Legitimation"                       
##  [2] "AFV.Manufacturer.Retrofitter"       
##  [3] "Acquisition...Fuel.Use"             
##  [4] "Aftermarket.Conversions"            
##  [5] "Air.Quality...Emissions"            
##  [6] "Alternative.Fuel.Dealer"            
##  [7] "Alternative.Fuel.Producer"          
##  [8] "Alternative.Fuel.Purchaser"         
##  [9] "Climate.Change...Energy.Initiatives"
## [10] "Exemptions"                         
## [11] "Fleet.Purchaser.Manager"            
## [12] "Fuel.Economy...Efficiency"          
## [13] "Fuel.Production...Quality"          
## [14] "Fuel.Taxes"                         
## [15] "Fueling...TSE.Infrastructure.Owner" 
## [16] "Grants"                             
## [17] "Idle.Reduction"                     
## [18] "Loans.and.Leases"                   
## [19] "Rebates"                            
## [20] "Registration...Licensing"           
## [21] "Renewable.Fuel.Standard...Mandate"  
## [22] "Tax.Incentives"                     
## [23] "Vehicle.Owner.Driver"               
## [24] "Car.Ownership"
dim(data3)
## [1] 918  24
### Using complete cases without NA
data4 <- data3[complete.cases(data3),]
dim(data4)
## [1] 867  24
### checking correlation
library(corrplot)
corrp <- cor(data4)
corrplot(corrp, method = "circle")

Important variable

### Using randomforest to find important variables
library(randomForest)
## randomForest 4.6-10
## Type rfNews() to see new features/changes/bug fixes.
data4.rf <- randomForest(Legitimation ~ ., data=data4, ntree=100, keep.forest=FALSE, importance=TRUE)
varImpPlot(data4.rf)

Algorithmic Modeling

index     <- 1:nrow(data4)
testindex <- sample(index, trunc(length(index)/3))
testset   <- data4[testindex,]
trainset  <- data4[-testindex,]
dim(testset)
## [1] 289  24
dim(trainset)
## [1] 578  24
library(e1071)
svm.model <- svm(Legitimation ~ ., data = data4, cost = 100, gamma = 1)
svm.pred  <- predict(svm.model, testset[,-1])


### Original vs. Predicted plot
plot(testset$Legitimation, svm.pred)