Analysis of RT distributions with R

19
Analysis of RT distributions with R Emil Ratko-Dehnert WS 2010/ 2011 Session 04 – 30.11.2010

description

Analysis of RT distributions with R. Emil Ratko-Dehnert WS 2010/ 2011 Session 04 – 30.11.2010. Last time. Random variables (RVs) Definition and examples (-> mapping from Ω to R) Calculus and distributions (-> additivity, multiplicity, ...) Characterization of RVs - PowerPoint PPT Presentation

Transcript of Analysis of RT distributions with R

Page 1: Analysis of RT distributions with R

Analysis of RT distributionswith R

Emil Ratko-DehnertWS 2010/ 2011

Session 04 – 30.11.2010

Page 2: Analysis of RT distributions with R

Last time ...

• Random variables (RVs)

– Definition and examples (-> mapping from Ω to R)

– Calculus and distributions (-> additivity, multiplicity, ...)

• Characterization of RVs

– By moments and descriptives (-> Mean, Var, Mode,Median)

2

Page 3: Analysis of RT distributions with R

RANDOM VARIABLES &THEIR CHARACTERIZATION

3

II

Page 4: Analysis of RT distributions with R

Recap: E(X), Var(X)

• „What is the expected (long term) outcome of X?“

• „How much do the values of a RV X vary around its mean value X ?“

4

i

ii xPxXE )(:)(

i

ii XxpXXEXVar 22 )()()(

II

Page 5: Analysis of RT distributions with R

Calculus for E(X)

• E( X + c ) = E( X ) +c (scalar additivity)

• E( X + Y ) = E( X ) + E( Y ) (linearity)

• E( a*X ) = a*E( X ) (scalar multipl.)

However(!):

• E( X * Y ) ≠ E( X ) * E( Y ) (non-multiplicity)

II

5

Page 6: Analysis of RT distributions with R

Calculus for Var(X)

• Var( X ) = E( X2 ) – ( E( X )2 ) (alternative formula)

• Var( a * X + b ) = a2 * Var( X ) (scalar „additivity“)

• Var( X + Y ) = Var( X ) + Var( Y ) + 2 * Cov( X,Y )

• Var( Σ Xi ) = Σ Var( Xi ), Xi uncorr.(Bienaymé)

II

6

Page 7: Analysis of RT distributions with R

Further properties of RVs

• Covariance Cov(X, Y)

• Correlation Corr(X, Y)

• Independance of RV‘s

• Identically distributedness of RV‘s

II

7

IID

Page 8: Analysis of RT distributions with R

Covariance Cov(X, Y)

• „The Covariance of RV‘s X and Y is a measure

of how much they change together“

• The standardized covariance is the Correlation

Corr(X,Y)

8

))(()((),( YEYXEXEYXCov

II

Page 9: Analysis of RT distributions with R

Correlation Corr(X, Y)

• One way of standardizing leads to the Pearson‘s

correlation coefficient

Don‘t confuse this with causality!

Neither confuse it with linearity!

9

II

YXYX

YXYXcorr

),cov(),(,

Page 10: Analysis of RT distributions with R

Example: Correlations (1)

10

II

Page 11: Analysis of RT distributions with R

Example: Correlations (2)

11

IICo

rr(X

,Y) =

0.8

16 f

or a

ll

Page 12: Analysis of RT distributions with R

Independance of RV‘s

• Two RV‘s X and Y are said to be independant,

if their expectations factorize:

• Then:

12

II

)()()( YEXEYXE

)()()( YVarXVarYXVar

Page 13: Analysis of RT distributions with R

Independance and Covariance

• If X, Y are independant, their covariance is zero

• Warning! The converse is generally not true:

i.e. X, Y can have Cov(X,Y) = 0 and not be

independant.

13

II

Page 14: Analysis of RT distributions with R

Identical distribution

• Two RV‘s X and Y are said to be identically

distributed, if they share the same distribution:

E.g.: X ~ N(0,1) and Y ~ N(0,1) are identically

distributed

• Ergo: each observation can be treated like it was

taken from the exact same distribution as the other14

II

Page 15: Analysis of RT distributions with R

Examples: IID RVs

• a sequence of outcomes of spins

of a roulette wheel is IID

• a sequence of dice rolls is IID

• a sequence of coin flips is IID

• RTs are often treated as IID events, though

this is rarely checked and frequently violated15

II

Page 16: Analysis of RT distributions with R

Significance of IID

• IID assumption important for many reasons

• In our case most importantly

– identical conditions across trials should have the

same effect (no intertrial or position effects!)

– Required for law of large numbers and central

limit theorem

– Required for many statistical tests (e.g. z-test)16

II

Page 17: Analysis of RT distributions with R

AND NOW TO

17

Page 18: Analysis of RT distributions with R

Creating own functionsnew.fun <- function(arg1, arg2, arg3){

x <- exp(arg1)

y <- sin(arg2)

z <- mean(arg2, arg3)

result <- x + y + z

result

}

A <- new.fun(12, 0.4, -4)18

„inputs“

„output“

Algo

rithm

of f

uncti

on

Usage of new.fun

Page 19: Analysis of RT distributions with R

Using Loops in R

result <- matrix(NA, nrow = 20, ncol = 10)

for(i in 1:10){

xx <- rnorm(n = 10, mean = i, sd = 4)

result [c(1:20), i] <- xx

}

result 19

Create empty frame for loop

Fill columns of exp with xx

Running index of loop