10/17/2015330 lecture 31 STATS 330: Lecture 3. Class Rep ?????? ??????????? 10/17/2015330 lecture...

24
03/22/22 330 lecture 3 1 STATS 330: Lecture 3

Transcript of 10/17/2015330 lecture 31 STATS 330: Lecture 3. Class Rep ?????? ??????????? 10/17/2015330 lecture...

04/20/23 330 lecture 3 1

STATS 330: Lecture 3

Class Rep??????

???????????

04/20/23 330 lecture 3 2

04/20/23 330 lecture 3 3

Today’s lecture: More on Trellis graphics

Aim of the lecture:

To give you an idea of the scope of trellis graphics

To discuss several examples and show how Trellis graphics reveal important insights into the data

04/20/23 330 lecture 3 4

Recall last time: Last lecture we discussed coplots: Coplots show how the relationship

between 2 variables x and y changes as the value of a third variable z changes

We can generalize this to more than one variable z: i.e. conditioning on more than one variable

04/20/23 330 lecture 3 5

Coplots: syntax

plot ( y~x | z*w)

Plot type – one of xyplotdotplotbwplot

X and y are the “relationship”

variables

Z and w are the “conditioning”

variables, can be missing

04/20/23 330 lecture 3 6

Conditioning on two variables

Suppose we have 2 conditioning variables Z and W.

No problem if both are categorical If one or both are continuous variables, we

turn them into categorical variables by using subranges e.g.– turn ages into 10 yr age groups – turn marks into grades

04/20/23 330 lecture 3 7

Two variables: contExample: age and sex. Sex is already categorical

Age not, so divide up the age range as0-17, 18-59, 60+

This gives a 3 x 2 table with 6 “cells”:

F M

0-17

18-59

60+

04/20/23 330 lecture 3 8

Relationship between x and y

In each of the 6 “cells” of the table, we can draw a graph that illustrates the relationship between x and y for individuals having that age and sex

Type of graph will depend on the type of x and y i.e. continuous/categorical– Both continuous: scatterplot– One continuous: boxplots, dotplots, etc

04/20/23 330 lecture 3 9

x & y continuous: xyplot

xyplot(y~x|age*sex)

x

y

8

10

12

18 20 22 24

F60+

M60+

F18-59

8

10

12

M18-59

8

10

12

F0-17

M0-17

18 20 22 24

04/20/23 330 lecture 3 10

x categorical, y continuous: dotplot

Y is continuous, X has 2 levels, “A” and “B”

dotplot(y~x|age*sex)

y

8

10

12

A B

F60+

A B

M60+

F18-59

8

10

12

M18-59

8

10

12

F0-17

M0-17

04/20/23 330 lecture 3 11

x categorical, y continuous: bwplot

Y continuous, X has 2 levels, “A” and “B”

bwplot(y~x|age*sex)y

8

10

12

A B

F60+

A B

M60+

F18-59

8

10

12

M18-59

8

10

12

F0-17

M0-17

04/20/23 330 lecture 3 12

To summarize: The conditioning variables determine the

layout of the “cells”

The x/y variables determine the kind of graph to draw in each cell

04/20/23 330 lecture 3 13

Example: sports In a study on athletes at the Australian Institute

of Sport, various physical measurements were made.

In this example we look at the relationship between body fat and BMI and how it differs between athletes of either sex playing different sports. BMI = weight(kg) / height(m)2

04/20/23 330 lecture 3 14

Data sex sport BMI X.Bfat1 female BBall 20.56 19.752 female BBall 20.67 21.303 female BBall 21.86 19.884 female BBall 21.88 23.665 female BBall 18.96 17.646 female BBall 21.04 15.587 female BBall 21.69 19.998 female BBall 20.62 22.439 female BBall 22.64 17.9510 female BBall 19.44 15.07

… more data (158 lines in all)

04/20/23 330 lecture 3 15

BMI

X.B

fat

5

10

15

20

25

30

20 25 30 35

Athleticsfemale

BBallfemale

20 25 30 35

Rowfemale

Swimfemale

20 25 30 35

Tennisfemale

Athleticsmale

BBallmale

20 25 30 35

Rowmale

Swimmale

20 25 30 35

5

10

15

20

25

30Tennismale

04/20/23 330 lecture 3 16

Example: engines In a study of engine emissions, a test engine

was run under different conditions and the amount of nitrogen oxide (NOx) emitted was measured.

The conditions involved different settings of the compression ratio C, and the Equivalence ratio, E (related to fuel/air mixture)

04/20/23 330 lecture 3 17

Data> ethanol.df NOx C E1 3.741 12.0 0.9072 2.295 12.0 0.7613 1.498 12.0 1.1084 2.881 12.0 1.0165 0.760 12.0 1.1896 3.120 9.0 1.0017 0.638 9.0 1.2318 1.170 9.0 1.1239 2.358 12.0 1.04210 0.606 12.0 1.21511 3.669 12.0 0.93012 1.000 12.0 1.15213 0.981 15.0 1.13814 1.192 18.0 0.601

… more data (88 lines)

How does NOx relate to E? does the relationship depend on C?

There are only 5 settings of C

(7.5, 9.0, 12.0, 15.0, 18.0)

so we condition on these.

04/20/23 330 lecture 3 18

E

NO

x

1

2

3

4

0.6 0.8 1 1.2

C C

0.6 0.8 1 1.2

C

C C

0.6 0.8 1 1.2

04/20/23 330 lecture 3 19

0.6 0.7 0.8 0.9 1.0 1.1 1.2

12

34

E

NO

x

C= 7.5C= 9.0C=12.0C=15.0C=18.0

04/20/23 330 lecture 3 20

Example: Yarn In an experiment to test the strength of

different yarns, lengths of yarn are repeatedly stressed until they break (cycles to failure).It is desired to see yow this variable is related to the length of the yarn samples, and the amplitude and the load (two variables related to the amount of stress). The experiment involved using 3 amplitudes, 3 lengths and 3 loads, for a total of 27 = 3 x 3 x 3 different experimental conditions. (Coursebook p 9)

Testing procedure

04/20/23 330 lecture 3 21

length

Load = ForceAmplitude

Cycles to failure: number of “pushes” before yarn breaks

04/20/23 330 lecture 3 22

Yarn data> cycles.df cycles length amplitude load1 674 low low low2 370 low low med3 292 low low high4 338 low med low5 266 low med med6 210 low med high7 170 low high low8 118 low high med9 90 low high high10 1414 med low low

… more data (27 lines in all)

04/20/23 330 lecture 3 23

cycles

leng

th

low

med

high

0 1000 2000 3000

amp: lowload: low

amp: medload: low

0 1000 2000 3000

amp: highload: low

low

med

high

amp: lowload: med

amp: medload: med

amp: highload: med

low

med

high

amp: lowload: high

amp: medload: high

0 1000 2000 3000

amp: highload: high

Conclusions For longer lengths, the cycles to failure are

higher. ( less likely to break) High loads reduce the cycles to failure

(more likely to break) High amplitudes reduce the cycles to

failure (more likely to break) Most likely to break when load and

amplitude are high and length is low

04/20/23 330 lecture 3 24