Showing posts with label R. Show all posts
Showing posts with label R. Show all posts

20.2.07

Using jayridge.eda()

I uploaded the R script here:
http://jayridge.googlepages.com/jayridge.eda.R

Now u can use it by sourcing the file from within R. This example shows how to load the function and generates a nonsensical plot from within the R console. ;)

cheers!


source("http://jayridge.googlepages.com/jayridge.eda.R")
jayridge.eda(rnorm(20), "Random Deviates")

19.2.07

jayridge.eda()

I spent a little time today writing a generic eda function in R. R is way hip but the graphics take a bit of tweaking. My particular problem was that I wanted a small footprint graphic that would give me a good idea of distribution of a univariate data set... that I wouldn't be ashamed of presenting to the executive types. Here is the function:


jayridge.eda<-function(x, title) {
# This function is based on simple.eda from the book,
# "Using R for Introdcutory Statistics", by John Verzani
#
# I found that the general function was useful but needed
# better titling and formatting for use in EDA presentations.

op<-par(no.readonly = TRUE); # save old parameters
par(mai=c(.6,.5,.2,.2))
par(family="sans")
par(cex.lab=1.2)

# Create a layout with two rows. The first row spans
# 3 columns.
#
# [,1] [,2] [,3]
# [1,] 1 1 1
# [2,] 2 3 4

layout(matrix(c(1,1,1,2,3,4), ncol=3, byrow=TRUE), heights=c(1,2))

# Frame 1: print the title, date and
plot.new()
plot.window(xlim=c(0,1), ylim=c(0,1))
title(main=title, cex.main=2)
f<-as.character(summary(x))
fStr<-sprintf("%9s %9s %9s %9s %9s %9s\n%9s %9s %9s %9s %9s %9s",
"Min","1st Qu","Median","Mean","3rd Qu","Max",
f[1],f[2],f[3],f[4],f[5],f[6])
text(0.5,0.5, labels=fStr, cex=1.4, adj=.5, family="mono")

# Frame 2: plot a histogram.
hist(x, main="Histogram", xlab=title, col="orange")
rug(x)

# Frame 3: plot a boxplot.
boxplot(x, varwidth=TRUE, col="orange", border="grey30")
rug(x,side=2)
title("Boxplot")

# Frame 4: plot a normal QQ.
qqnorm(x, col="grey30")
qqline(x,col="red")

par(op); # reset old parameters
}


And here is the fabulous output!

13.2.07

Segmented Barplot using R

I've started working on an Exploratory Data Analysis (EDA) for share2me, now that real live folk (as opposed to us tech weenies) are sharing stuff. Naturally, being a statistician at heart I went straight to http://www.r-project.org/ to download the latest rev of R.

My first goal was simply to get back on the bike and start pedaling. In stats this amounts to some judicious select statements and data loading (statistics doesn't have the same issue shortening the name as fraternities). Then typing two lines of code:


x<-read.csv("~/R/data/inconspicuous.csv", header=F)
barplot(table(x[,1],x[,3]), main="Inconspicuous Segmented Barplot", col=rainbow(20,start=.1,end=.8), axisnames=F)


results in the following fabulously segmented barplot... totally bitchen!