We’re into the fourth day of Business Science Demo Week. We have a really cool one in store today: tibbletime, which uses a new tbl_time class that is time-aware!! For those that may have missed it, every day this week we are demo-ing an R package: tidyquant (Monday), timetk (Tuesday), sweep (Wednesday), tibbletime (Thursday) and h2o (Friday)! That’s five packages in five days! We’ll give you intel on what you need to know about these packages to go from zero to hero. Let’s take tibbletime for a spin!
Previous Demo Week Demos
class(Monday) %
gather(key = key, value = value, adj_min, adj_max, adj_med) # Plot using our plotting function, grouping by key (min, max, and median)
FANG_min_max_by_2m %__%
ggplot_facet_by_symbol(date, value, group = key) +
geom_point() +
labs(title = &quot;Summarizing Data By 2-Months (Bi-Monthly)&quot;,
subtitle = &quot;2~m&quot;)
Those interested in furthering their understanding of time_summarise() can check out the time_summarise function documentation.
as_period The next function, as_period(), enables changing the period of a tbl_time object. Two advantages to using this method over traditional approaches:
The functions are flexible: “yearly” == “y” == “1~y”
The functional notation allows for endless periodicity change combinations, for example:
“15~d” to change to 15-day periodicity
“2~m” to change to bi-monthly periodicity
“4~m” to change to tri-annual (semesters or trimesters)
“6~m” to change to bi-annual
To start off, let’s do a simple monthly periodicity change.
# Convert from daily to monthly periodicity
FANG_tbl_time_d %__%
as_period(period = &quot;month&quot;) %__%
# Plotting
ggplot_facet_by_symbol(date, adjusted) +
labs(title = &quot;Periodicity Change from Daily to Monthly&quot;) +
geom_point()
Let’s step it up a notch. What about bi-monthly? Just use the functional notation, “2~m”.
# Convert from daily to bi-monthly periodicity
FANG_tbl_time_d %__%
as_period(period = 2~m) %__%
# Plotting
ggplot_facet_by_symbol(date, adjusted) +
labs(title = &quot;Periodicity Change to Daily to Bi-Monthly&quot;,
subtitle = &quot;2~m&quot;) +
geom_point()
Let’s keep going. What about bi-annually? Just use “6~m”.
# Convert from daily to bi-monthly periodicity
FANG_tbl_time_d %__%
as_period(period = 6~m) %__%
# Plotting
ggplot_facet_by_symbol(date, adjusted) +
labs(title = &quot;Periodicity Change to Daily to Bi-Annually&quot;,
subtitle = &quot;6~m&quot;) +
geom_point()
The possibilities are endless with the functional notation. Interested learners can check out the vignette on periodicity change with tibbletime.
rollify The rollify() function is an adverb (a special type of function in the tidyverse that modifies another function). What rollify() does is turn any function into a rolling version of itself.
# Rolling 60-day mean
roll_mean_60 %
mutate(mean_60 = roll_mean_60(adjusted)) %__%
select(-c(open:volume)) %__%
# Plot
ggplot_facet_by_symbol(date, adjusted) +
geom_line(aes(y = mean_60), color = palette_light()[[6]]) +
labs(title = &quot;Rolling 60-Day Mean with rollify&quot;)
We can even do more complicated rolling functions such as correlations. We use the functional form .f = ~ fun(.x, .y, ...) within rollify().
# Rolling correlation
roll_corr_60 %
mutate(cor_60 = roll_corr_60(open, close)) %__%
select(-c(open:adjusted)) %__%
# Plot
ggplot_facet_by_symbol(date, cor_60) +
labs(title = &quot;Rollify: 60-Day Rolling Correlation Between Open and Close Prices&quot;)
We can even return multiple results. For example, we can create a rolling quantile.
First, create a function that returns a tibble of quantiles.
# Quantile tbl function
quantile_tbl %
unnest()
FANG_quantile_60## # A time tibble: 13,940 x 4
## # Index: date
## # Groups: symbol [4]
## symbol date quantile_name quantile_value
## * ## 1 FB 2014-03-28 0% 53.5300
## 2 FB 2014-03-28 25% 57.8750
## 3 FB 2014-03-28 50% 64.2100
## 4 FB 2014-03-28 75% 68.6275
## 5 FB 2014-03-28 100% 72.0300
## 6 FB 2014-03-31 0% 53.5300
## 7 FB 2014-03-31 25% 57.9350
## 8 FB 2014-03-31 50% 64.2100
## 9 FB 2014-03-31 75% 68.6275
## 10 FB 2014-03-31 100% 72.0300
## # ... with 13,930 more rowsFinally, we can plot the results.
FANG_quantile_60 %__%
ggplot_facet_by_symbol(date, quantile_value, group = quantile_name) +
labs(title = &quot;Rollify: Create Rolling Quantiles&quot;)
Interested learners can continue exploring rollify by checking out our vignette on rolling functions with rollify.
Changes Coming
This package is currently under active development. Don’t be shocked if the functionality increases soon… Davis Vaughan is working hard to expand the capability of tibbletime. Reproducible bug reports are welcome!
Next Steps
Interested learners can check out the following links to further understanding of tibbletime:
Business Science Software Website
tibbletime documentation
tibbletime GitHub Page
Business Science Insights Blog
Announcements We have a busy couple of weeks. In addition to Demo Week, we have:
DataTalk
!!TONIGHT!! Thursday, October 26 at 7PM EST, Matt will be giving a FREE LIVE #DataTalk on Machine Learning for Recruitment and Reducing Employee Attrition. You can sign up for a reminder at the Experian Data Lab website.
#MachineLearning for Reducing Employee Attrition @BizScienchttps://t.co/vlxmjWzKCL#ML #AI #HR #IoTT #IoT #DL #BigData #Tech #Cloud #Jobs pic.twitter.com/dF5Znf10Sk— Experian DataLab (@ExperianDataLab) October 18, 2017
EARL
On Friday, November 3rd, Matt will be presenting at the EARL Conference on HR Analytics: Using Machine Learning to Predict Employee Turnover.
😀Hey #rstats. I'll be presenting @earlconf on #MachineLearning applications in #HumanResources. Get 15% off tickets: https://t.co/b6JUQ6BSTl— Matt Dancho (@mdancho84) October 11, 2017
Courses
Based on recent demand, we are considering offering application-specific machine learning courses for Data Scientists. The content will be business problems similar to our popular articles:
HR Analytics: Using Machine Learning to Predict Employee Turnover
Sales Analytics: How To Use Machine Learning to Predict and Optimize Product Backorders
The student will learn from Business Science how to implement cutting edge data science to solve business problems. Please let us know if you are interested. You can leave comments as to what you would like to see at the bottom of the post in Disqus.
About Business Science Business Science specializes in “ROI-driven data science”. Our focus is machine learning and data science in business applications. We help businesses that seek to add this competitive advantage but may not have the resources currently to implement predictive analytics. Business Science works with clients primarily in small to medium size businesses, guiding these organizations in expanding predictive analytics while executing on ROI generating projects. Visit the Business Science website or contact us to learn more!
Follow Business Science on Social Media @bizScienc is on twitter!
Check us out on Facebook page!
Check us out on LinkedIn!
Sign up for our insights blog to stay updated!
If you like our software, star our GitHub packages!