G.Janacek - R stuff

The computer is an essential tool in most of our courses and we shall use a package called R developed by Robert Gentleman and Ross Ihaka. There is almost all the information you require about R at the CRAN site

R is available in the BIO-Maths lab and on most of of the the ITSC lab PC's.

The stuff below is a collection of notes and code to help in using R. Much of it is to help me to remember how to do things I last did some time ago.

Connected to glm

  • If you want to set the scale or the dispersion, for example so as to set the dispersion to 1 use dispersion=1 as a parameter to summary viz.
    summary(r1,dispersion=1)
  • If you need the covariance of the parameter coefficients in a glm the following function is useful
    vcov.glm<-function(obj)
    {
    so<-summary(obj)
    so$dispersion*so$cov.unscaled
    }
    vcov.glm( glm object)
    gives the required variance covariance matrix

    General

  • It helps when using nlm to increase the heap space

    Time Series

    There is some time series stuff, in particular the Timeslab routines of Newton and the recent time series library. My own R routines are here
    here
  • A note from the mailing list
    From: Joerg Maeder
    Subject: Re: [R] multiple series on same graph
    Hello Collin,
    The thing with different colors, symbols or size is very easy. Just give a vector with as many elements as points you want to the function points.
    points(c(x1,x2,x3,x4,x5),c(y1,y1,y2,y3,y4,y5),col=c(col1,col2,col3,col4,col5),phc=(pch1,pc...),cex=c(....))
    the same thing also works in plot, text, lines and so on, and also for the arguments lty (line typ) If your vector is too short it will be duplicated as many time as neccessary. In this case col=c('black','blue') will produce alternating colors. with legends i don't have much experience. I often do it with 'text' and 'points'. But there is a function called legend. I should also have to look to it.

    R PostgreSQL Package

    The RPgSQL package for R allows users to read and write data frames to and from a postgresql database. No knowledge of SQL is necessary to use the postgres package. However, a low-level interface is also provided for sending SQL queries to the postgresql backend, and retrieving results. The package also has support for "proxy" data frames. A data frame proxy is an R object that inherits from the data.frame class, but contains no data. All accesses to the proxy data frame generate the appropriate SQL query and retrieve the resulting data from the postgresql backend. When this interface is complete, you will be able to process arbitrarily large data frames without loading everything into memory. You can find information about postgresql here