analysis of r elationship between two variables

11
catter plots are simple but yet ery powerful presentations of wo variables and how they are elated. wo sets of random variables contain he coordinates of the sample oints. R-Code: plot() arguments: pch=3 tells plot() to use ‘+’ as symbol cex=0.3 scales the size of the symbol + x 2 (k) =0.32 x 1 (k)=0.65 R has built-in random number generators: Samples can be drawn using functions Uniform distribution: runif() Gaussian distribution: rnorm() Samples drawn from uniform distribut

Upload: imala

Post on 03-Feb-2016

53 views

Category:

Documents


0 download

DESCRIPTION

Analysis of r elationship between two variables. Samples drawn from uniform distributions. Scatter plots are simple but yet very powerful presentations of two variables and how they are related. Two sets of random variables contain the coordinates of the sample points. x 2 (k) =0.32. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Analysis of  r elationship between two variables

Scatter plots are simple but yetvery powerful presentations oftwo variables and how they are related.Two sets of random variables containthe coordinates of the samplepoints.

R-Code: plot() arguments:

pch=3 tells plot() to use ‘+’ as symbol cex=0.3 scales the size of the symbol

+x2(k)=0.32

x1(k)=0.65

R has built-in random number generators:Samples can be drawn using functionsUniform distribution: runif()Gaussian distribution: rnorm()

Samples drawn from uniform distributions

Page 2: Analysis of  r elationship between two variables

Scatter plots are simple but yetvery powerful presentations oftwo variables and how they are related.Two sets of random variables containthe coordinates of the samplepoints.

R-Code: plot() arguments:

pch=3 tells plot() to use ‘+’ as symbol cex=0.3 scales the size of the symbol

Samples drawn from Gaussian distributions

Page 3: Analysis of  r elationship between two variables

Albany monthly mean temperature anomalies and New York Central Parktemperature anomalies 1950-2010

Albany NY Central Park

Whenever two variables are sampled along a ‘physically meaningful’ dimensionsuch as time, repeated controlled experiments, or geographic coordinates, we candefine pairs of data. These pairs form a 2-dimensional coordinate system => Scatter diagram.

Page 4: Analysis of  r elationship between two variables

Albany monthly mean temperature anomalies and New York Central Parktemperature anomalies 1950-2010

R-Code:x is a vector with Albany temperature anomaliesy is a vector with Central Park temp. anomalies.Elements in the vectors x, y at position k share the same time coordinate and form a data pair.Plotting a point symbol ‘+’ requires 2 coordinates:The x-coordinates comes from vector xThe y-coordiantes comes from vector y

Page 5: Analysis of  r elationship between two variables

Regression lines are the simplest functionsthat we can try to fit with the data. In this example the relationship between the twotemperature time series is obviously linearand can be well fitted by a linear regressionline. R-Code:x is a vector with Albany temperature anomaliesy is a vector with Central Park temp. anomalies.

The function lm( y ~ x ) {lm short name for ‘linear model’} is used for ‘Ordinary Least Squares Regression Analysis’

Page 6: Analysis of  r elationship between two variables

Vectors in R:

y<-c(x1,x2,x3,…xn)

Page 7: Analysis of  r elationship between two variables

R-Code:

Another common notation for vector dot products

Page 8: Analysis of  r elationship between two variables

Another common notation for vector dot products

Page 9: Analysis of  r elationship between two variables
Page 10: Analysis of  r elationship between two variables

Equivalent to the R notation as seen in graph:

abs( mean(x1) – mean(x2) )/ sqrt ( sd(x1) * sd(x2) )

In this example mean(x1) = -1 and mean(x2) = +1; sd(x1) = 1 and sd(x2) = 1 The equation gives a value of 2. That is the difference is 2 times the length ofthe (geometrically averaged) samples standard deviations.

Page 11: Analysis of  r elationship between two variables

With the function par() we can manipulateThe plot appearance in many ways (see help(par))The function is usually called at the begin of a script, or Right before a plotting function.For example to split the plot window into a 2x2 panel of

subfigures:

par(mfrow=c(2,2))

NOTE: You must call par(mfrow=c(1,1)) again to get the single-figure mode back.