# Holcombe:ProgrammingInR

(Difference between revisions)
 Revision as of 01:15, 2 December 2009 (view source)← Previous diff Revision as of 01:11, 3 December 2009 (view source)Next diff → Line 5: Line 5: In the lab we have the book ''Using R for Introductory Statistics''. [[R_Statistics]] introduces you to R In the lab we have the book ''Using R for Introductory Statistics''. [[R_Statistics]] introduces you to R + + Dani has posted some example code and graphs on his [http://www.dlinares.org/Site/R_code.html personal website]. [http://www.rpad.org/Rpad/R-refcard.pdf R reference cheatsheet], also [http://www.rpad.org/Rpad/R-refcard.pdf R reference cheatsheet], also Line 38: Line 40: see Swindale, N. V. (1998). Orientation tuning curves: empirical description and estimation of parameters. Biol Cybern, 78(1), 45-56. see Swindale, N. V. (1998). Orientation tuning curves: empirical description and estimation of parameters. Biol Cybern, 78(1), 45-56. + + ==Creating Graphs== + In the lab we usually use the package, [http://had.co.nz/ggplot2/ ggplot2], for graphs. Ask Sarah about the ggplot2 book. ==Setting up a proxy in R on a Mac== ==Setting up a proxy in R on a Mac==

## Revision as of 01:11, 3 December 2009

### Members

Alex Holcombe
Sarah McIntyre
Fahed Jbarah
• Shih-Yu Lo
• Patrick Goodbourn
Lizzy Nguyen
Alumni

### Other

R is an interactive programming language for statistics. The syntax is very idiosyncratic, and not really in a good way. Try R for programmers for a description. However it may have menu-driven versions maybe available R commander we haven't tried that and another one is pmg GTK maybe here

In the lab we have the book Using R for Introductory Statistics. R_Statistics introduces you to R

Dani has posted some example code and graphs on his personal website.

R reference cheatsheet, also a file here Media:Matlab-python-xref.pdf‎ that gives equivalent code for doing array operations in MATLAB, Python, and R plot parameters

There is a wiki with some good tips here. Also Data frame tips, list of R websites

Functions in R can only return one parameter. Calling typeof() on a dataframe returns "list"! Delete nearly everything in memory: rm(list = ls())

Examining your data matrix or object, let's say it's called datos

```head(datos)
str(datos)
```

Don't use the function attach. It seems to leave lots of data in the 'environment' that can cause problems later. Also it makes the code harder to understand.

## fitting psychometric functions

Malte Kuss hosts the R library PsychoFun on his personal webpage rather than c-ran server. So you must download is package, unzip it, and install it by going to R->Packages&Data->Package Installer->Local Package Directory->Install, go inside the PsychoFun directory you've unzipped, and click Open.

I needed to constrain width of psychometric function to be quite narrow. Prior I was using followed lognormal distribution. Then if want mode to be say .1, have to feed it a mean parameter of -2.3 because ln(.1) = -2. Unfortunately the PsychoFun code doesn't allow using a negative parameter for that prior, so I had to change the code. To do so, you go into the downloaded version of PsychoFun folder before you install it, where you can find PsychoFun.R in the R subdirectory. I commented out line 56. Then have to reinstall with Install manager inside R, after in my case first deleting original PsychoFun installation in /Library/Frameworks/R.framework/Versions/2.10/Resources/library/

## doing ANOVAs etc

I think I had too many error terms reducing error terms

## Dealing with circular data

von Mises vs. wrapped Gaussian,

see Swindale, N. V. (1998). Orientation tuning curves: empirical description and estimation of parameters. Biol Cybern, 78(1), 45-56.

## Creating Graphs

In the lab we usually use the package, ggplot2, for graphs. Ask Sarah about the ggplot2 book.

## Setting up a proxy in R on a Mac

The easiest way to set up a proxy is simply to create a file called ".Rprofile" in your user directory (~ or Users/username/) with the line: ``` ```

``` Sys.setenv(http_proxy=”http://username:password@tcdproxy.tcd.ie:8080″) ```

Then restart R. This information (and more) can be found on Ken Benoit's webpage

For Sydney Uni, use: ``` ```

``` Sys.setenv(http_proxy=”http://www-cache.usyd.edu.au:8080″) ```