Posts Tagged ‘ code ’

The truncated Poisson

February 21, 2010
By
The truncated Poisson

A common model for counts data is the Poisson. There are cases however that we only record positive counts, ie there is a truncation of 0. This is the truncated Poisson model. To study this model we only need the total counts and the sample size. This comes from the sufficient statistic principle as the

Read more »

Uh!

February 20, 2010
By

Didn't know this... a data 0 2 4 7+ 25 34 12 5 It's becoming clear that I have learned R in the most unstructured way...I always do it in two stages :ashamed:

Read more »

Barnard’s exact test – a powerful alternative for Fisher’s exact test (implemented in R)

February 7, 2010
By
Barnard’s exact test – a powerful alternative for Fisher’s exact test (implemented in R)

(The R code for Barnard’s exact test is at the end of the article, and you could also just download it from here) About Barnard’s exact test About half a year ago, I was studying various statistical methods to employ on contingency tables. I came across a promising method for 2×2 contingency tables called “Barnard’s exact test“. Barnard’s test is a non-parametric alternative to Fisher’s exact...

Read more »

R> if (done=TRUE) tweet me!

December 11, 2009
By
R> if (done=TRUE) tweet me!

Let’s say that you’re fitting a cumbersome model so time is not to waste over a PC staring at the screen half anxious-half bored… Then, you can always leave and go on with meetings and all your daily routine and have R notify you the results! How? We will illustrate the situation above using some Bayesian Model

Read more »

Create factor variables in R

December 6, 2009
By
Create factor variables in R

Instead of the factor() function which usually applies after defining a vector there’s the gl() base function to do this in one step, eg freq <- c(204,6,1,211,13,5,357,44,38,92,34,49) row <- gl(4,3,length=12) col <- gl(3,1,length=12) > col 1 2 3 1 2 3 1 2 3 1 2 3 Levels: 1 2 3 tt <- data.frame(freq,row,col) > xtabs(tt) col row   1   2   3 1 204   6  

Read more »

Tactical asset allocation using blotter

November 18, 2009
By
Tactical asset allocation using blotter

blotter is an R package that tracks the P&L of your trading systems (or simulations), even if your portfolio spans many security types and/or currencies. This post uses blotter to track a simple two-ETF trading system. The contents of this post b...

Read more »

Confidence we seek…

November 18, 2009
By
Confidence we seek…

Estimating a proportion at first looks elementary. Hail to aymptotics, right? Well, initially it might seem efficient to iuse the fact that . In other words the classical confidence interval relies on the inversion of Wald’s test. A function to ease the computation is the following (not really needed!). waldci<- function(x,n,level){ phat<-sum(x)/n results<-phat + c(-1,1)*qnorm(1-level/2)*sqrt(phat*(1-phat)/n) print(results) } An exact confidence interval is

Read more »

Show me the mean(ing)…

November 5, 2009
By
Show me the mean(ing)…

Well testing a bunch of samples for the largest population mean isn’t that common yet a simple test is at hand. Under the obvious title “The rank sum maximum test for the largest K population means” the test relies on the calculation of the sum of ranks under the combined sample of size , where

Read more »

Corpus Linguistics with R, Day 2

July 28, 2009
By

R Lesson 2 text gsub ("second", "third", text) SEARCH-REPLACE-SUBJECT "This is a first example sentence." "And this is a third example sentence." > gsub ("n", "X", text) "This is a first example seXteXce." "AXd this is a secoXd example seXteXce." > gsub ("is", "was", text) "Thwas was a first example

Read more »

Corpus Linguistics with R, Day 1

July 28, 2009
By

(This post documents the first day of a class on R that I took at ESU C&T. I is posted here purely for my own use.) R Lesson 1 > 2+3; 2/3; 2^3 5 0.6666667 8 --- Fundamentals - Functions > log(x=1000, base=10) 3 --- (Formals describes the syntax of other

Read more »