Matlab - missing data Flashcards

1
Q

Real life psychology experiments often suffer from missing data - you may want to exclude trials
where reaction times fall outside some limits, or where the subject made an error. In Matlab, you can
do this using NaN. NaN stands for Not A Number and can be used in any vector or matrix in place of
missing data. In general, it is much better to replace your missing data with NaNs than to delete it
altogether. When you use NaN, some of the basic functions like sum and mean will no longer work as
10
you expect, but Matlab provides alternate versions, nansum, nanmean and nanstd which let you
ignore NaNs and find the sum, mean and standard deviation of your data

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

if
» err = [1 0 0 0 0 0 0 1 0 1 0 0];

how would you replace an error (1s) using NaN?

A

data(err==1) = NaN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

using the cat data:
» data = [4 14 6 11 3 14 8 17 17 12 10 18];
» cat = [1 3 2 1 2 2 3 1 3 2 3 1];
» cat2 = cat==2
cat2 = 0 0 1 0 1 1 0 0 0 1 0 0
» data2 = data(cat2);
data2 = 6 3 14 12

an additional vector err has a one at every error:
err = [1 0 0 0 0 0 0 1 0 1 0 0];

how would you code so that every error is replaced with a NaN?

A

data(err==1) = NaN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

how would you find the mean following this line of code?
» data2 = data(cat2);
data2 = 6 3 14 NaN

A

> > mdat2 = nanmean(data2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly