This is an example of Tableau and R integration. Here, I am using a machine learning technique to predict the winner of 2012 election using polling data from likely voters. The data is from RealClearPolitics.com and basically represents polling data that was collected in the months leading up to the 2004 and 2008 US presidential election. Using logistic regression (a machine learning technique), I predicted for 2012. Then, we can access the performance of our model using various metrics.
In this exercise, I imported the data to Tableau and wrote an R code inside Tableau, which is shown below.
SCRIPT_REAL('mydata <- data.frame(Rep=.arg1, survey=.arg2, diffc=.arg3); lrmodel <- glm(Rep ~ survey + diffc, data = mydata, family = "binomial"); prob <- predict(lrmodel, newdata = mydata, type = "response")', AVG([Republican]),AVG([SurveyUSA]),AVG([Diff Count]))
We can integrate R and Tableau for text data mining in social media analysis, big data analytics, machine learning, predictive modeling, statistical modeling, etc., by taking advantage of the numerous R packages. Then, using Tableau will be painless for generating amazing visualizations.
In the dashboard below, the figure at the top is probability of a Republican party winning as predicted from a logistic regression. we can take probabilities greater than 0.50 as success (Republican) and probability values of 0.5 and below as Democrat. The figure at the bottom shows actual elections. As we can clearly observe from the dashboard, the model has a very good performance.