March 2014

MCMC for Econometrics Students – III

March 19, 2014 | Dave Giles

As its title suggests, this post is the third in a sequence of posts designed to introduce econometrics students to the use of Markov Chain Monte Carlo (MCMC, or MC2) methods for Bayesian inference. The first two posts can be found here and here, and I'll assume that you've read ... [Read more...]

Dynamic dispatch for sparse matrices

March 19, 2014 | Rcpp Gallery

We want to do matrix multiplication for 3 cases: dense times dense sparse times dense for sparse matrices of class dgCMatrix sparse times dense for sparse matrices of class indMatrix, using R’s Matrix package for sparse matrices in R and RcppArmadillo for C++ linear algebra:
<span>// [[Rcpp::depends(RcppArmadillo)]]</span>
<span>#include <RcppArmadillo.h></span>
<span>using</span> <span>namespace</span> <span>Rcpp</span> <span>;</span>

<span>arma</span><span>::</span><span>mat</span> <span>matmult_sp</span><span>(</span><span>const</span> <span>arma</span><span>::</span><span>sp_mat</span> <span>X</span><span>,</span> <span>const</span> <span>arma</span><span>::</span><span>mat</span> <span>Y</span><span>){</span>
    <span>arma</span><span>::</span><span>mat</span> <span>ret</span> <span>=</span> <span>X</span> <span>*</span> <span>Y</span><span>;</span>
    <span>return</span> <span>ret</span><span>;</span>
<span>};</span>
<span>arma</span><span>::</span><span>mat</span> <span>matmult_dense</span><span>(</span><span>const</span> <span>arma</span><span>::</span><span>mat</span> <span>X</span><span>,</span> <span>const</span> <span>arma</span><span>::</span><span>mat</span> <span>Y</span><span>){</span>
    <span>arma</span><span>::</span><span>mat</span> <span>ret</span> <span>=</span> <span>X</span> <span>*</span> <span>Y</span><span>;</span>
    <span>return</span> <span>ret</span><span>;</span>
<span>};</span>
<span>arma</span><span>::</span><span>mat</span> <span>matmult_ind</span><span>(</span><span>const</span> <span>SEXP</span> <span>Xr</span><span>,</span> <span>const</span> <span>arma</span><span>::</span><span>mat</span> <span>Y</span><span>){</span>
    <span>// pre-multiplication with index matrix is a permutation of Y's rows: </span>
    <span>arma</span><span>::</span><span>uvec</span> <span>perm</span> <span>=</span>  <span>as</span><span><</span><span>S4</span><span>></span><span>(</span><span>Xr</span><span>).</span><span>slot</span><span>(</span><span>"perm"</span><span>);</span>
    <span>arma</span><span>::</span><span>mat</span> <span>ret</span> <span>=</span> <span>Y</span><span>.</span><span>rows</span><span>(</span><span>perm</span> <span>-</span> <span>1</span><span>);</span>
    <span>return</span> <span>ret</span><span>;</span>
<span>};</span>

<span>//[[Rcpp::export]]</span>
<span>arma</span><span>::</span><span>mat</span> <span>matmult_cpp</span><span>(</span><span>SEXP</span> <span>Xr</span><span>,</span> <span>const</span> <span>arma</span><span>::</span><span>mat</span> <span>Y</span><span>)</span> <span>{</span>
    <span>if</span> <span>(</span><span>Rf_isS4</span><span>(</span><span>Xr</span><span>))</span> <span>{</span>
        <span>if</span><span>(</span><span>Rf_inherits</span><span>(</span><span>Xr</span><span>,</span> <span>"dgCMatrix"</span><span>))</span> <span>{</span>
            <span>return</span> <span>matmult_sp</span><span>(</span><span>as</span><span><</span><span>arma</span><span>::</span><span>sp_mat</span><span>></span><span>(</span><span>Xr</span><span>),</span> <span>Y</span><span>)</span> <span>;</span>
        <span>}</span> <span>;</span>
        <span>if</span><span>(</span><span>Rf_inherits</span><span>(</span><span>Xr</span><span>,</span> <span>"indMatrix"</span><span>))</span> <span>{</span>
            <span>return</span> <span>matmult_ind</span><span>(</span><span>Xr</span><span>,</span> <span>Y</span><span>)</span> <span>;</span> 
        <span>}</span> <span>;</span>
        <span>stop</span><span>(</span><span>"unknown class of Xr"</span><span>)</span> <span>;</span>
    <span>}</span> <span>else</span> <span>{</span>
        <span>return</span> <span>matmult_dense</span><span>(</span><span>as</span><span><</span><span>arma</span><span>::</span><span>mat</span><span>></span><span>(</span><span>Xr</span><span>),</span> <span>Y</span><span>)</span> <span>;</span>
    <span>}</span> 
<span>}</span>
Set up test cases: {{...
[Read more...]

Stop using bivariate correlations for variable selection

March 19, 2014 | Jacob Simmering

Stop using bivariate correlations for variable selection Something I've never understood is the widespread calculation and reporting of univariate and bivariate statistics in applied work, especially when it comes to model selection. Bivariate statistics are, at best, useless for multi-variate model selection and, at worst, harmful. Since nearly all questions ... [Read more...]

fine-sliced Poisson [a.k.a. sashimi]

March 19, 2014 | xi'an

As my student Kévin Guimard had not mailed me his own Poisson slice sampler of a Poisson distribution, I could not tell why the code was not working! My earlier post prompted him to do so and a somewhat optimised version is given below: As you can easily check ... [Read more...]

The #rBlocks Experiments

March 19, 2014 | Jo-fai Chow

What's this ? Where should I start? OK, the story goes like this ... rBlocks: A port of #ipythonblocks to #rstats http://t.co/iMMRPCxQIN @simplystats @gvwilson @hadleywickham pic.twitter.com/6LQmN4LZWM— Ramnath Vaidyanathan (@ramnath_vaidya) March 12, 2014 Colouring #rstats df with @ramnath_vaidya #rBlocks Iris revisited http://t.co/TFDDXGK7y2 ... [Read more...]

Using R: barplot with ggplot2

March 19, 2014 | mrtnj

Ah, the barplot. Loved by some, hated by some, the first graph you’re likely to make in your favourite office spreadsheet software, but a rather tricky one to pull off in R. Or, that depends. If you just need a barplot that displays the value of each data point ... [Read more...]

Build Web applications using Shiny R

March 19, 2014 | suresh kumar Gorakala

Ever since I’ve started working on R , I always wondered how I can presentthe results of my statistical models as web applications. After doing someresearch over the internet I’ve come across – ShinyR – a new packagefrom RStudio which can be used to develop interactive web applications with R.Before ... [Read more...]

Shiny-server Open Source Edition: Solution for CPU Bound Apps

March 19, 2014 | Huidong Tian

Shiny-server integrates the statistic power of R with web, convenients the statistical analysis through web. Users can do complecate statistical anlysis through their web browsers. However, most of statistical analysis of R are CPU bound computation, that means CPU utilization is high, perhaps at 100% for many seconds. This leads to ... [Read more...]

MCMC for Econometrics Students – II

March 18, 2014 | Dave Giles

This is the second in a set of posts about Monte Carlo Markov Chain (MCMC, or MC2) methods in Bayesian econometrics. The background was provided in this first post, where the Gibbs sampler was introduced. The main objective of the present post is to convince you that this MCMC stuff ... [Read more...]

Dynamic arrays in R, Python and Julia

March 18, 2014 | tlfvincent

Although I have a heavy background in statistics (and therefore am primarily an R user), I find that my overall knowledge in computer science is generally lacking. Therefore, I have recently delved deeper into learning about data structures, their associated ADT’s and how they can be implemented. At the ... [Read more...]

Secrets of Teaching R

March 18, 2014 | Joseph Rickert

by James Paul Peruvankal, Senior Program Manager at Revolution Analytics At Revolution Analytics, we are always interested in how people teach and learn R, and what makes R so popular, yet ‘quirky’ to learn. To get some insight from a real pro we interviewed Bob Muenchen. Bob is the author ... [Read more...]

How popular is the President of Mexico on Twitter?

March 18, 2014 | Jose

Twitter simultaneously allows people to be heard and to hear, easily and in real time, bringing with it potentially fascinating and ground breaking insights for anybody trying to take the public’s pulse on a hot issue.  It is almost mandatory that so much benefit comes with its challenges, namely ...
[Read more...]

Timeline charts with googleVis

March 18, 2014 | Markus Gesmann

Last year at the Google I/O conference Mitchell Foley presented new developments of the Google Chart Tools API and one of the new features he mentioned were timeline charts (about 6 min into the talk). Timeline charts are a great way of visualising different dates/events over time and are ... [Read more...]

Cover of my forecasting textbook

March 18, 2014 | Rob J Hyndman

We now have a cover for the print version of my forecasting book with George Athanasopoulos. It should be on Amazon in a couple of weeks. The book is also freely available online. This is a variation of the most popular one in the poll conducted a mon... [Read more...]
1 4 5 6 7 8 15

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)