Shiny Data Product on Vehicle Purchase Behavior

I used the nested multinomial logit module that I developed for my dissertation to develop this data product to predict what kind of vehicle would someone likely purchase in the future, depending on their characteristics, and the infrastructure availability. 

I designed three tabs of results, with the input options in drop down menu on the left-hand side.

The user can choose their attributes in the drop-down menu: the options include (a) the year they want to purchase the car, (b) what kind of driving pattern they typically have, (c) how do they feel about new technologies in general, and their recharging availability at home and work. 

There are two kinds of scenarios I developed for this exercise. One is the baseline scenario, where the government does not invest in any public charging stations, and a "good infrastructure" scenario, where there is more initiative to install public chargers and other alternative fuel stations. These two tabs show the top three car technologies that the consumer would be more willing to purchase giving the circumstances. The third tab gives time series plots of vehicle purchases of this consumer for these two scenarios, i.e., it shows the purchase probability of all the vehicle technologies.

 Timeseries plots

Timeseries plots

The live data product link can be found here.  And, the github repository for the R code is here.

The goal of this exercise is to show how your attributes and behavior can influence your vehicle technology purchase, and also, how incentives such as public charger installation can help promote the cleaner cars into the vehicle mix.

Creating GeoJSON data from CSV and Shapefiles

I got a lot of CSV data from US Census for a recent spatial data project I've been working on. In order to visualize the data using Leaflet or other equivalent tools, we may have to create a GeoJSON data file that we can import into the Javascript code.

I have been exploring zip code level data for this project, so I was able to obtain the shapefile of zip codes from US Census website. The next step is to merge all the other CSV files I got to this shapefile using zip code as the common id.

QGIS has an easy method to perform this. Once we bring in the required shapefile in QGIS, we can add another layer, but this time, we are adding the CSV file as an attribute table only layer:

After we locate the CSV file, another window pops up to provide options for this addition. Here, we have to make sure to select the "No Geometry (attribute table only)" option, so that it will be added as a table to the map.

Now, when we right click on the shapefile and click on 'Properties', we should be able to see the "Joins" function. We can add a new join using the "+" sign at the bottom of this window. Here, we need to select the appropriate column names that QGIS can use to join the table to the shapefile. In this case, I am giving the names of the zip code column data in both data sources.

Once we finish adding that, we can right click and open the attribute table of the shapefile and can see that the CSV file values are merged with the shapefile accordingly. 

The next step is to export this new data source to a GeoJSON file. 

When we right-click on this shapefile, choose 'save as', it takes us to a new window, where we can choose the format of how we want to save it:

Choose 'GeoJSON' and save the file!