R tutorial The big picture. R is an open source version of the S-Plus scripting language R is a rich statistical environment that includes a programming language, an interactive shell, and extensive graphing capability.

ugliestharrasSoftware and s/w Development

Nov 4, 2013 (3 years and 9 months ago)

93 views

R tutorial


The big picture.

R is an open source version of the S
-
Plus
scripting
language


R is a rich statistical environment that includes a programming language, an interactive
shell, and extensive graphing capability.


# To see a list of demo scripts

d
emo()


# To run a specific demo

demo(graphics)


# Command line examples

# Build a vector of numbers

x <
-

c(1,2,3,4,5,6,7,8)

x


# Divide every element in the vector by 2

x/2


# Show simple summary statistics for vector x

summary(x)



# Two methods demonstra
ting the mean calculation

mean(x)

sum(x)/length(x)



# Generating numbers

# The Normal Distribution

y

<
-

rnorm(100)


# Extracting a sub
-
vector

z <
-

y
[1:10]


# Boolean output

z <
-
0.5


#
Build a vector of x data for p
lotting

x

<
-

1:length(
y
)


#
A simple p
lot example

plot(x,y
)



----------------------------------------


# The big picture;

# This is an example of data visualization to illustrate the accuracy of calculations.


#
Show all e
xample data sets included with R

data()


# Notice the data set named pr
essure

#
pressure Vapor Pressure of Mercury as a Function of

#

Temperature



# Make the pressure data set accessible

data(pressure)


# Show the data

pressure


# Show the names of the data columns

names(pressure)


# Plot the data with labels

plot(pressur
e$temperature,pressure$pressure, main="Relationship Between Temperature
and vapor pressure", xlab="Temperature",ylab="Vapor Pressure")


# Add a lowess line to the plot

lines(lowess(pressure$pressure ~ pressure$tempe
rature, f=
0
.
05
), col = 3)


# Problem; what is the vapor pressure of mercury at temperature 310?


# Loess (lowess) is a Modern regression method that combines much of the simplicity of
# linear least squares regression with the flexibility of nonlinear reg
ression.

# It works by fitting simple models to localized subsets of the data
.

#
LOESS (aka LOWESS)

#
http://www.itl.nist.gov/div898/handbook/pmd/section1/pmd144.htm


# Make a loess object

merc.loess <
-

loess(pressure$pressure ~ pressure$temperature
, span
= 0.75
)


# Using the loess fit

data to

predict the pressure at a given temperature

preAtTemp1 = predict(merc.loess, newdata=data.frame(temperature = 310))


preAtTemp2 = predict(merc.loess, newdata=data.frame(temperature = 330))


# Place a red
diamond
poi
nt on the graph

points(310, preAtTemp1, col = “red”
,pch=23)


# Why doesn’t the point fall on the green lowess line?

# How do we fix this?



# Place a blue triangle point on the graph

points(330, preAtTemp2, col = “blue”
,pch=22)


---------------------------
-----------

# Simple t
-
test example


x <
-

c(104,116,84,77,61,84,81,72,61,97,84)

y <
-

c(108,118,89,71,66,83,88,76,68,96,81)


t.test(x, y, alternative="greater", mu=0, paired=T, conf.level=.95)

--------------------------------------



microArrayDataExample.r




R Tutorial

http://www.cyclismo.org/tutorial/R/

http://www.cyclismo.org/tutorial/R/input.html


##
------------------------------------
##

## Script for Part 1: Orientation ##

## John Fox ##

## An Introduction to R

##

## UCLA Feb. 2005 ##

##
------------------------------------
##


http://socserv.socsci.mcmaster.ca/jfox/Courses/UCLA/Part
-
1
-
script.R


Bioinformatics Zen, How to draw simple graphs in R

http://www.bioinformaticszen.com/2007/05/bioinf
ormatics
-
simple
-
graphs
-
in
-
r/



LOESS (aka LOWESS)

http://www.itl.nist.gov/div898/handbook/pmd/section1/pmd144.htm