March 2013

The most worthwhile R coding guidelines I know

March 2, 2013 | Derek Jones

Since my post questioning whether native R usage exists (e.g., a common set of R coding patterns) several people have asked about coding/style guidelines for R. My approach to style/coding guidelines is economic, adhering to a guideline involves paying a cost now for some future benefit. Obviously ... [Read more...]

Distribution of T-Scores

March 2, 2013 | Wesley

Like most of my post these code snippets derive from various other projects.  In this example it shows a simulation of how one can determine if a set of t statistics are distributed properly.  This can be useful when sampling known populations (e.g. U.S. census or hospital populations) ... [Read more...]

PCA to PLS modeling analysis strategy for WIDE DATA

March 2, 2013 | dgrapov

Working with wide data is already hard enough, add to this row outliers and things can get murky fast. Here is an example of an anlysis of a wide data set, 24 rows  x 84 columns. Using imDEV, written in R, to calculate and visualize a principal components analysis (PCA) on this ... [Read more...]

About This Blog

March 2, 2013 | Isaac

About This BlogMy name is Isaac and I'm a Ph.D. student in Clinical Psychology. Why am I writing about fantasy football and data analysis? Because fantasy football involves the intersection of two things I love: sports and statistics. With this blog, I... [Read more...]

Percentage Winner

March 2, 2013 | Thomas Huben

I know, it has been often said by people, much brighter and more competent that I will ever be. The least important figure to look at are the Percentage Winner.Personally I find it very challenging and difficult to follow a system - or even provide see... [Read more...]

RcppArmadillo 0.3.800.0

March 2, 2013 | Thinking inside the box

A new Armadillo version 3.800.0 is now out. Conrad picked a new numbering scheme to coincide with the relicensing from LGPL to MPL 2.0. The new version 0.3.800.0 of the corresponding RcppArmadillo package (which still uses GPL 2 or later) is now on ... [Read more...]

The options mechanism in R

March 2, 2013 | Patrick Burns

Customization in R. Basics Several features benefit from being customizable — either because of personal taste or specifics of the environment. The way R implements this flexibility is through the options function.  This both sets and reports options.  For example, we can see the names of the options that are set ... [Read more...]

making a random walk geometrically ergodic

March 1, 2013 | xi'an

While a random walk Metropolis-Hastings algorithm cannot be uniformly ergodic in a general setting (Mengersen and Tweedie, AoS, 1996), because it needs more energy to leave far away starting points, it can be geometrically ergodic depending on the target (and the proposal). In a recent Annals of Statistics paper, Leif Johnson ... [Read more...]

Tools for making a paper

March 1, 2013 | Will

Since it seems to be the fashion, here’s a post about how I make my academic papers. Actually, who am I trying to kid? This is also about how I make slides, letters, memos and “Back in 10 minutes” signs to pin on the door. Nevertheless it’s for making ... [Read more...]

R 2.15.3 is released

March 1, 2013 | Tal Galili

Follows is the announcement today from Peter Dalgaard, for the R Core Team: The build system rolled up R-2.15.3.tar.gz (codename “Security Blanket”) at 9:00 [Read more...]

Using ENCODE methylation data (RRBS) in R

March 1, 2013 | l2n

ENCODE project has generated reduced-representation bilsulfite sequencing data for multiple cell lines. The data is organized in an extended bed format with additional columns denoting % methylation and coverage per base. Luckily, this sort of generic... [Read more...]

Counts may be ratio, but not importance

March 1, 2013 | Joel Cadwell

I can see from those of you who have contacted me that there is still some confusion about the claims made by Sawtooth that MaxDiff estimates can be converted to ratio-scale probabilities.  Many of you seem to believe that if attribute A... [Read more...]

Data Visualization: Shiny Spiced Consulting

March 1, 2013 | Sean Gonzalez

If you haven’t already heard, RStudio has developed an incredibly easy way to deploy R on the web with its Shiny Package. For those who have heard, this really isn’t new as bloggers have already been blogging about it for some … Continue reading → The post Data Visualization: Shiny ... [Read more...]

Overlapping Histogram in R

March 1, 2013 | arsalvacion

While preparing a class exercise involving the use of overlaying of histogram, I searched Google on possible article or discussion on the said topic. Luckily, I found a blog where the author demonstrated an R function to create an overlapping histogram... [Read more...]

Using Rcpp with Boost.Regex for regular expression

March 1, 2013 | Rcpp Gallery

Gabor asked about Rcpp use with regular expression libraries. This post shows a very simple example, based onone of the Boost.RegEx examples. We need to set linker options. This can be as simple as
Sys.setenv<span>(</span><span>"PKG_LIBS"</span><span>=</span><span>"-lboost_regex"</span><span>)</span>
With that, the following example can be built:
<span>// cf www.boost.org/doc/libs/1_53_0/libs/regex/example/snippets/credit_card_example.cpp</span>

<span>#include <Rcpp.h></span>

<span>#include <string></span>
<span>#include <boost/regex.hpp></span>

<span>bool</span> <span>validate_card_format</span><span>(</span><span>const</span> <span>std</span><span>::</span><span>string</span><span>&</span> <span>s</span><span>)</span> <span>{</span>
   <span>static</span> <span>const</span> <span>boost</span><span>::</span><span>regex</span> <span>e</span><span>(</span><span>"(</span><span>\\</span><span>d{4}[- ]){3}</span><span>\\</span><span>d{4}"</span><span>);</span>
   <span>return</span> <span>boost</span><span>::</span><span>regex_match</span><span>(</span><span>s</span><span>,</span> <span>e</span><span>);</span>
<span>}</span>

<span>const</span> <span>boost</span><span>::</span><span>regex</span> <span>e</span><span>(</span><span>"</span><span>\\</span><span>A(</span><span>\\</span><span>d{3,4})[- ]?(</span><span>\\</span><span>d{4})[- ]?(</span><span>\\</span><span>d{4})[- ]?(</span><span>\\</span><span>d{4})</span><span>\\</span><span>z"</span><span>);</span>
<span>const</span> <span>std</span><span>::</span><span>string</span> <span>machine_format</span><span>(</span><span>"</span><span>\\</span><span>1</span><span>\\</span><span>2</span><span>\\</span><span>3</span><span>\\</span><span>4"</span><span>);</span>
<span>const</span> <span>std</span><span>::</span><span>string</span> <span>human_format</span><span>(</span><span>"</span><span>\\</span><span>1-</span><span>\\</span><span>2-</span><span>\\</span><span>3-</span><span>\\</span><span>4"</span><span>);</span>

<span>std</span><span>::</span><span>string</span> <span>machine_readable_card_number</span><span>(</span><span>const</span> <span>std</span><span>::</span><span>string</span><span>&</span> <span>s</span><span>)</span> <span>{</span>
   <span>return</span> <span>boost</span><span>::</span><span>regex_replace</span><span>(</span><span>s</span><span>,</span> <span>e</span><span>,</span> <span>machine_format</span><span>,</span> <span>boost</span><span>::</span><span>match_default</span> <span>|</span> <span>boost</span><span>::</span><span>format_sed</span><span>);</span>
<span>}</span>

<span>std</span><span>::</span><span>string</span> <span>human_readable_card_number</span><span>(</span><span>const</span> <span>std</span><span>::</span><span>string</span><span>&</span> <span>s</span><span>)</span> <span>{</span>
   <span>return</span> <span>boost</span><span>::</span><span>regex_replace</span><span>(</span><span>s</span><span>,</span> <span>e</span><span>,</span> <span>human_format</span><span>,</span> <span>boost</span><span>::</span><span>match_default</span> <span>|</span> <span>boost</span><span>::</span><span>format_sed</span><span>);</span>
<span>}</span>

<span>// [[Rcpp::export]]</span>
<span>Rcpp</span><span>::</span><span>DataFrame</span> <span>regexDemo</span><span>(</span><span>std</span><span>::</span><span>vector</span><span><</span><span>std</span><span>::</span><span>string</span><span>></span> <span>s</span><span>)</span> <span>{</span>
    <span>int</span> <span>n</span> <span>=</span> <span>s</span><span>.</span><span>size</span><span>();</span>
    
    <span>std</span><span>::</span><span>vector</span><span><</span><span>bool</span><span>></span> <span>valid</span><span>(</span><span>n</span><span>);</span>
    <span>std</span><span>::</span><span>vector</span><span><</span><span>std</span><span>::</span><span>string</span><span>></span> <span>machine</span><span>(</span><span>n</span><span>);</span>
    <span>std</span><span>::</span><span>vector</span><span><</span><span>std</span><span>::</span><span>string</span><span>></span> <span>human</span><span>(</span><span>n</span><span>);</span>
    
    <span>for</span> <span>(</span><span>int</span> <span>i</span><span>=</span><span>0</span><span>;</span> <span>i</span><span><</span><span>n</span><span>;</span> <span>i</span><span>++</span><span>)</span> <span>{</span>
        <span>valid</span><span>[</span><span>i</span><span>]</span>  <span>=</span> <span>validate_card_format</span><span>(</span><span>s</span><span>[</span><span>i</span><span>]);</span>
        <span>machine</span><span>[</span><span>i</span><span>]</span> <span>=</span> <span>machine_readable_card_number</span><span>(</span><span>s</span><span>[</span><span>i</span><span>]);</span>
        <span>human</span><span>[</span><span>i</span><span>]</span> <span>=</span> <span>human_readable_card_number</span><span>(</span><span>s</span><span>[</span><span>i</span><span>]);</span>
    <span>}</span>
    <span>return</span> <span>Rcpp</span><span>::</span><span>DataFrame</span><span>::</span><span>create</span><span>(</span><span>Rcpp</span><span>::</span><span>Named</span><span>(</span><span>"input"</span><span>)</span> <span>=</span> <span>s</span><span>,</span>
                                   <span>Rcpp</span><span>::</span><span>Named</span><span>(</span><span>"valid"</span><span>)</span> <span>=</span> <span>valid</span><span>,</span>
                                   <span>Rcpp</span><span>::</span><span>Named</span><span>(</span><span>"machine"</span><span>)</span> <span>=</span> <span>machine</span><span>,</span>
                                   <span>Rcpp</span><span>::</span><span>Named</span><span>(</span><span>"human"</span><span>)</span> <span>=</span> <span>human</span><span>);</span>
<span>}</span>
We can test the function ...
[Read more...]
1 12 13 14

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)