Blog Archives

Parsing Dates and Times

March 21, 2015
By
Parsing Dates and Times

Motivation R has excellent for dates and times via the built-in Date and POSIXt classes. Their usage, however, is not always as straightforward as one would want. Certain conversions are more cumbersome than we would like: while as.Date("2015-03-22"), would it not be nice if as.Date("20150322") (a format often used in logfiles) also worked, or for that matter as.Date(20150322L) using an integer variable, or...

Read more »

Create an R-tree data structure using Rcpp and Boost::Geometry

December 26, 2014
By
Create an R-tree data structure using Rcpp and Boost::Geometry

Introduction The purpose of this post is to show how to use Boost::Geometry library which was introduced recently in Rcpp. Especially, we focus on R-tree data structure for searching objects in space because only one spatial index is implemented - R-tree Currently in this library. Boost.Geometry which is part of the Boost C++ Libraries gives us algorithms for solving geometry problems. In this library, the...

Read more »

Sampling Importance Resampling (SIR) and social revolution.

October 22, 2014
By
Sampling Importance Resampling (SIR) and social revolution.

Motivation The purpose of this gallery post is several fold: to demonstrate the use of the new and improved C++-level implementation of R’s sample() function (see here) to demonstrate the Gallery’s new support for images in contributed posts to demonstrate the usefulness of SIR for updating posterior beliefs given a sample from an arbitrary prior distribution Application: Foreign Threats and Social Revolution The...

Read more »

Implementing an EM Algorithm for Probit Regressions

September 30, 2014
By
Implementing an EM Algorithm for Probit Regressions

Users new to the Rcpp family of functionality are often impressed with the performance gains that can be realized, but struggle to see how to approach their own computational problems. Many of the most impressive performance gains are demonstrated with seemingly advanced statistical methods, advanced C++–related constructs, or both. Even when users are able to understand how various demonstrated features operate in isolation, examples...

Read more »

Using RcppArmadillo with bigmemory

July 24, 2014
By
Using RcppArmadillo with bigmemory

The bigmemory package allows users to create matrices that are external to R, stored either in RAM or on disk, allowing them to be bigger than the system RAM, and allowing them to be shared across R sessions. While these objects are defined by the big.matrix class in R, they are really just wrappers that point to external memory. The actual objects are implemented...

Read more »

Parallel Distance Matrix Calculation with RcppParallel

July 14, 2014
By
Parallel Distance Matrix Calculation with RcppParallel

The RcppParallel package includes high level functions for doing parallel programming with Rcpp. For example, the parallelFor function can be used to convert the work of a standard serial “for” loop into a parallel one. This article describes using RcppParallel to compute pairwise distances for each row in an input data matrix and return an n x n lower-triangular distance matrix which...

Read more »

Computing an Inner Product with RcppParallel

July 14, 2014
By
Computing an Inner Product with RcppParallel

The RcppParallel package includes high level functions for doing parallel programming with Rcpp. For example, the parallelReduce function can be used aggreggate values from a set of inputs in parallel. This article describes using RcppParallel to parallelize the inner-product example previously posted to the Rcpp Gallery. Serial Version First the serial version of computing the inner product. For this we use a...

Read more »

Summing a Vector in Parallel with RcppParallel

June 28, 2014
By
Summing a Vector in Parallel with RcppParallel

The RcppParallel package includes high level functions for doing parallel programming with Rcpp. For example, the parallelReduce function can be used aggreggate values from a set of inputs in parallel. This article describes using RcppParallel to sum an R vector. Serial Version First a serial version of computing the sum of a vector. For this we use a simple call to the STL std::accumulate function: #include...

Read more »

Transforming a Matrix in Parallel using RcppParallel

June 28, 2014
By
Transforming a Matrix in Parallel using RcppParallel

The RcppParallel package includes high level functions for doing parallel programming with Rcpp. For example, the parallelFor function can be used to convert the work of a standard serial “for” loop into a parallel one. This article describes using RcppParallel to transform an R matrix in parallel. Serial Version First a serial version of the matrix transformation. We take the square root of each...

Read more »

Speed Chain Ladder Analysis with Rcpp

June 23, 2014
By
Speed Chain Ladder Analysis with Rcpp

The Chain Ladder method is an actuarial technique used for projecting incurred insurance claims to their ultimate loss values. The data exists as claims triangles where the claims for each accounting year increments down the rows and the claims for eac...

Read more »