April 2013

austerity in MCMC land (#2)

April 29, 2013 | xi'an

After reading the arXiv paper by Korattikara, Chen and Welling, I wondered about the expression of the acceptance step of the Metropolis-Hastings algorithm as a mean of log-likelihoods over the sample. More specifically the long sleepless nights at the hospital led me to ponder the rather silly question of the ... [Read more...]

Editing/Adding factor levels in R

April 29, 2013 | Shreyes

I was trying to change few levels in my factor variable by simply coercing characters on that factor variable but it dint seem to work.
data(iris)<br>iris$Species[c(50:120)] <- rep("Random", 71)<br>
## Warning: invalid factor level, NAs generated<br>
iris$Species<br>
##   [1] setosa    setosa    setosa    setosa    setosa    setosa    setosa   <br>##   [8] setosa    setosa    setosa    setosa    setosa    setosa    setosa   <br>##  [15] setosa    setosa    setosa    setosa    setosa    setosa    setosa   <br>##  [22] setosa    setosa    setosa    setosa    setosa    setosa    setosa   <br>##  [29] setosa    setosa    setosa    setosa    setosa    setosa    setosa   <br>##  [36] setosa    setosa    setosa    setosa    setosa    setosa    setosa   <br>##  [43] setosa    setosa    setosa    setosa    setosa    setosa    setosa   <br>##  [50] <NA>      <NA>      <NA>      <NA>      <NA>      <NA>      <NA>     <br><br>##  [57] <NA>      <NA>      <NA>      <NA>      <NA>      <NA>      <NA>     <br>##  [64] <NA>      <NA>      <NA>      <NA>      <NA>      <NA>      <NA>     <br><br>##  [71] <NA>      <NA>      <NA>      <NA>      <NA>      <NA>      <NA>     <br>##  [78] <NA>      <NA>      <NA>      <NA>      <NA>      <NA>      <NA>     <br><br>##  [85] <NA>      <NA>      <NA>      <NA>      <NA>      <NA>      <NA>     <br>##  [92] <NA>      <NA>      <NA>      <NA>      <NA>      <NA>      <NA>     <br><br>##  [99] <NA>      <NA>      <NA>      <NA>      <NA>      <NA>      <NA>     <br>## [106] <NA>      <NA>      <NA>      <NA>      <NA>      <NA>      <NA>     <br><br>## [113] <NA>      <NA>      <NA>      <NA>      <NA>      <NA>      <NA>     <br>## [120] <NA>      virginica virginica virginica virginica virginica virginica<br>## [127] virginica virginica virginica virginica virginica virginica virginica<br>## [134] virginica virginica virginica virginica virginica virginica virginica<br>## [141] virginica virginica virginica virginica virginica virginica virginica<br>## [148] virginica virginica virginica<br>## Levels: setosa versicolor virginica<br><br>
Well, I did find a way to find a work around for that by doing this:
iris$Species <- as.character(iris$Species)<br>iris$Species[c(50:120)] <- rep("Random", 71)<br>iris$Species <- as.factor(iris$Species)<br>iris$Species<br>
##   [1] setosa    setosa    setosa    setosa    setosa    setosa    setosa   <br>##   [8] setosa    setosa    setosa    setosa    setosa    setosa    setosa   <br>##  [15] setosa    setosa    setosa    setosa    setosa    setosa    setosa   <br>##  [22] setosa    setosa    setosa    setosa    setosa    setosa    setosa   <br>##  [29] setosa    setosa    setosa    setosa    setosa    setosa    setosa   <br>##  [36] setosa    setosa    setosa    setosa    setosa    setosa    setosa   <br>##  [43] setosa    setosa    setosa    setosa    setosa    setosa    setosa   <br>##  [50] Random    Random    Random    Random    Random    Random    Random   <br>##  [57] Random    Random    Random    Random    Random    Random    Random   <br>##  [64] Random    Random    Random    Random    Random    Random    Random   <br>##  [71] Random    Random    Random    Random    Random    Random    Random   <br>##  [78] Random    Random    Random    Random    Random    Random    Random   <br>##  [85] Random    Random    Random    Random    Random    Random    Random   <br>##  [92] Random    Random    Random    Random    Random    Random    Random   <br>##  [99] Random    Random    Random    Random    Random    Random    Random   <br>## [106] Random    Random    Random    Random    Random    Random    Random   <br>## [113] Random    Random    Random    Random    Random    Random    Random   <br>## [120] Random    virginica virginica virginica virginica virginica virginica<br>## [127] virginica virginica virginica virginica virginica virginica virginica<br>## [134] virginica virginica virginica virginica virginica virginica virginica<br>## [141] virginica virginica virginica virginica virginica virginica virginica<br>## [148] virginica virginica virginica<br>## Levels: Random setosa virginica<br>
This problem annoyed ... [Read more...]

Citation Patterns in Ecology

April 29, 2013 | Nathan Lemoine

I’m always curious to see who is citing my one paper. Turns out I actually have two papers, and the most cited paper (with 19 citations, which sounds paltry but for me is quite exciting) is certainly not the one … Continue reading → [Read more...]

Stats in the Court Room Hands on Tutorial

April 29, 2013 | leisuretronic

I got intrigued by the numbers presented in this news article talking about the re-trial in the Amanda Knox case. The defendants, accused and initially convicted of murder, were acquitted in the appeal's instance when the judge ruled that the forensic evidence was insufficiently conclusive. The appeals judge ignored the ... [Read more...]

Slouching towards simulating investment skill

April 29, 2013 | Pat

When investment skill is simulated, it is often presented as if it is obvious how to do it.  Maybe I’m wrong, but I don’t think it’s obvious. Previously In “Simple tests of predicted returns” we saw that prediction quality need not look like what you would find ... [Read more...]

How to change the alpha value of colours in R

April 29, 2013 | Markus Gesmann

Often I like to reduce the alpha value (level of transparency) of colours to identify patterns of over-plotting when displaying lots of data points with R. So, here is a tiny function that allows me to add an alpha value to a given vector of colours, e.g. a RColorBrewer ... [Read more...]

Slides and exercise from my second R intro seminar

April 28, 2013 | mrtnj

This week I held the second introductory seminar on R, and I think it went pretty well — though I guess you really should ask my colleagues if you want to know. The first seminar was a lecture, and this seminar was a tutorial where we made some plots and calculated ... [Read more...]

Posteriors vs predictives

April 26, 2013 | Gianluca Baio

Karl Saliba writes with some queries about our football paper, which I have already discussed on the blog here. He says:Thanks to the code in the appendix I could easily replicate (by using WinBUGS) a similar analysis on any football league of my ... [Read more...]

Revolution Newsletter: April 2013

April 26, 2013 | David Smith

The most recent edition of the Revolution Newsletter is out. The news section is below, and you can read the full April edition (with highlights from this blog and community events) online. You can subscribe to the Revolution Newsletter to get it monthly via email. Now Available: Revolution R Enterprise 6.2. ... [Read more...]

Data Visualization: From Excel to ???

April 26, 2013 | Sean Gonzalez

So you’re an excel wizard, you make the best graphs and charts Microsoft’s classic product has to offer, and you expertly integrate them into your business operations.  Lately you’ve studied up on all the latest uses for data visualization and … Continue reading →The post Data Visualization: From ... [Read more...]

The Financial Crisis on Tape Part II

April 26, 2013 | Joe'sDataDiner

EDIT: I am aware of some browsers failing to load the github code below. I will try to improve this as soon as possible. Until then it may work better on www.joesdatadiner.com than at https://www.r-bloggers.com/. Finally all the code is availa... [Read more...]

Learning to code in R

April 25, 2013 | Luis

It used to be that the one of the first decisions to make when learning to program was between compiled (e.g. C or FORTRAN) and interpreted (e.g. Python) languages. In my opinion these days one would have to be a masochist to learn with a compiled language: the ... [Read more...]
1 2 3 4 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)