Posts Tagged ‘ functions ’

R-Function to Source all Functions from a GitHub Repository

January 1, 2012
By
R-Function to Source all Functions from a GitHub Repository

Here's a function that sources all scripts from an arbitrary github-repository. At the moment the function downloads the whole repo and sources functions kept in a folder named "Functions" - this may be adapted for everyones own purpose.R...

Read more »

R Function Binding Vectors and Matrices of Variable Length, bug fixed

August 19, 2011
By

Now this is something very geeky, but useful. I had to bind two matrices or vectors together to become a bigger matrix. However, they need not have the same number of rows or even the same row names. The standard cbind() functions require the vectors or matrices to be compatible. The matching is “stupid”,...

Read more »

Avoiding Loops in R: An Example with Principal Minors

July 18, 2011
By
Avoiding Loops in R: An Example with Principal Minors

Yesterday, I found myself wanting to compute a large subset of the second order principal minors of a matrix (diagonal-preserving minors; the ones for which the rows and columns kept are the same). Don't judge me for wanting to do this, and bear with ...

Read more »

Recreational R: Simulating a Card Trick

May 30, 2011
By
Recreational R: Simulating a Card Trick

In this post, I simulate an interesting card trick, which was described by a friend of mine named Xan. Here's Xan's description of the card trick:I put a deck of cards down face up on the table. Meanwhile you think of a secret number between 1 and 1...

Read more »

An Application of boot() to IV regression

May 28, 2011
By
An Application of boot() to IV regression

Bootstrapping standard errors can be a useful technique when obtaining closed form for the standard error formula is difficult or intractable. In this post, I give an example of how to use R to create a bootstrap sampling distribution in the context o...

Read more »

Defaults, Lists and Classes: A Functional Post

May 20, 2011
By
Defaults, Lists and Classes: A Functional Post

In this post, I demonstrate a couple of useful tricks to writing functions in R. The context is a function I wrote called called samp() that allows for an easy demonstration of sampling distribution properties.DefaultsBy default, this function draws K...

Read more »

R: Functions and environments and a debugging utility, oh my!

February 7, 2011
By
R: Functions and environments and a debugging utility, oh my!

The Mark Fredrickson blog has a superb post on R functions and environments that's well worth checking out.He also includes a handy function for debugging:> fnpeek fnpeek(f1, "n") 7

Read more »

Example 8.8: more Hosmer and Lemeshow

October 5, 2010
By
Example 8.8: more Hosmer and Lemeshow

This is a special R-only entry.In Example 8.7, we showed the Hosmer and Lemeshow goodness-of-fit test. Today we demonstrate more advanced computational approaches for the test.If you write a function for your own use, it hardly matters what it looks l...

Read more »

Dumping functions from the global environment into an R script file

September 15, 2010
By

Looking at a project you didn’t touch for years poses many challenges. The less documentation and organization you had in your files, the more time you’ll have to spend tracing back what you did back when the code was written. I just opened up such a project, that was before I ever knew to...

Read more »

Clustergram: visualization and diagnostics for cluster analysis (R code)

June 15, 2010
By
Clustergram: visualization and diagnostics for cluster analysis (R code)

About Clustergrams In 2002, Matthias Schonlau published in “The Stata Journal” an article named “The Clustergram: A graph for visualizing hierarchical and . As explained in the abstract: In hierarchical cluster analysis dendrogram graphs are used to visualize how clusters are formed. I propose an alternative graph named “clustergram” to examine how cluster members...

Read more »