2.2 Solutions

load(url("https://github.com/QMUL-SPIR/Public_files/raw/master/datasets/BSAS_manip.RData"))
  1. Use square brackets to access the first 10 rows in the 4th column of data2, which you should have loaded above.
  2. Use the dollar sign to access the Househld variable in data2.
  3. How would you describe the level of measurement of
    1. the religious variable?
    2. the IMMBRIT variable?
    3. the health.good variable?
  4. Find and describe the central tendency of the religious variable in data2, thinking about which measure is appropriate.
  5. Find and describe the dispersion of the religious variable in data2, thinking about which measure is appropriate.
  6. Find and describe the central tendency of the IMMBRIT variable in data2, thinking about which measure is appropriate.
  7. Find and describe the dispersion of the IMMBRIT variable in data2, thinking about which measure is appropriate.
  8. Find and describe the central tendency of the health.good variable in data2, thinking about which measure is appropriate.
  9. Find and describe the dispersion of the health.good variable in data2, thinking about which measure is appropriate.

2.2.1 Exercise 1

Use square brackets to access the first 10 rows in the 4th column of data2.

data2[10, 4]
[1] 61

2.2.2 Exercise 2

Use the dollar sign to access the Househld variable in data2.

data2$Househld
   [1] 2 3 1 2 1 4 2 1 4 3 1 1 1 2 1 1 1 5 2 1 2 3 4 5 2 1 5 2 4 1 2 2 2 2 5 4 2
  [38] 1 3 5 2 3 3 1 1 2 2 2 1 5 1 3 4 1 1 1 6 8 3 4 4 1 1 1 4 3 4 1 3 1 2 3 2 3
  [75] 1 2 5 2 2 2 2 3 3 2 2 2 5 2 3 3 4 1 3 3 3 2 1 1 3 1 4 2 2 1 4 2 4 2 1 1 2
 [112] 5 2 2 7 4 1 5 3 3 2 1 1 2 4 3 3 2 1 2 3 1 2 1 2 3 1 1 2 1 1 2 3 2 3 4 5 5
 [149] 4 2 2 1 3 3 2 2 1 2 2 3 2 1 1 2 2 5 2 3 2 5 2 2 2 3 1 2 3 1 2 1 1 1 4 2 2
 [186] 1 2 3 1 1 7 1 2 5 4 1 3 2 1 4 3 4 2 1 2 3 3 2 3 3 2 1 2 1 2 2 2 2 7 1 3 2
 [223] 1 1 1 3 4 2 1 2 7 1 2 4 1 1 1 3 2 1 2 2 2 1 4 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 2 4 1 1 2 4 4 4 2 2 2 2 2 4 3
 [741] 1 2 2 1 2 4 1 3 2 1 1 1 1 4 2 1 3 6 1 2 1 1 2 2 1 2 5 2 3 4 2 2 3 6 1 2 1
 [778] 1 2 6 5 3 2 2 4 1 3 2 6 1 1 1 2 4 2 1 5 1 1 1 1 1 2 4 3 5 2 2 1 3 3 4 3 2
 [815] 2 4 4 1 2 1 1 2 6 2 3 1 1 2 2 1 3 5 1 1 2 1 2 1 2 1 6 3 1 2 2 2 4 2 2 2 5
 [852] 3 1 4 2 7 1 1 3 2 6 2 2 1 1 1 2 2 4 2 3 3 1 4 1 2 2 1 3 2 1 4 1 3 3 1 2 3
 [889] 1 2 1 1 3 2 7 2 2 2 1 3 2 4 1 2 1 1 3 4 1 4 5 3 1 2 2 5 1 5 4 4 6 2 3 2 2
 [926] 1 4 1 2 2 1 5 3 4 4 5 2 3 2 1 5 4 2 4 2 3 1 1 2 2 2 4 2 3 1 4 2 4 2 3 2 5
 [963] 2 2 2 3 1 2 1 2 4 1 4 2 7 1 2 1 3 2 2 4 5 2 4 2 3 2 2 2 4 1 1 2 2 3 1 2 2
[1000] 4 1 1 2 2 2 4 1 3 4 1 1 1 1 4 1 2 1 1 1 1 1 2 2 1 1 1 2 3 3 1 2 2 1 2 1 2
[1037] 2 3 1 4 3 4 5 3 4 2 4 1 3

2.2.3 Exercise 3

How would you describe the level of measurement of the religious variable?

The religious variable is nominal, because it describes distinct categories which have no inherent order.

How would you describe the level of measurement of the IMMBRIT variable?

The IMMBRIT variable is continuous, because it is a number with consistent, equal intervals.

How would you describe the level of measurement of the health.good variable?

The health.good variable is ordinal, because it describes ordered levels which might have inconsistent intervals.

2.2.4 Exercise 4

Find and describe the central tendency of the religious variable in data2, thinking about which measure is appropriate.

table(data2$religious) # use table() to work out the mode

  0   1 
532 517 

2.2.5 Exercise 5

Find and describe the dispersion of the religious variable in data2, thinking about which measure is appropriate.

prop.table(table(data2$religious)) # proportion in each category

        0         1 
0.5071497 0.4928503 

2.2.6 Exercise 6

Find and describe the central tendency of the IMMBRIT variable in data2, thinking about which measure is appropriate.

mean(data2$IMMBRIT) # use mean() for a continuous variable
[1] 29.03051

2.2.7 Exercise 7

Find and describe the dispersion of the IMMBRIT variable in data2, thinking about which measure is appropriate.

sd(data2$IMMBRIT) # use sd() for a continuous variable
[1] 21.06331

2.2.8 Exercise 8

Find and describe the central tendency of the health.good variable in data2, thinking about which measure is appropriate.

median(data2$health.good) # use median() for an ordinal variable
[1] 2

2.2.9 Exercise 9

Find and describe the dispersion of the health.good variable in data2, thinking about which measure is appropriate.

quantile(data2$health.good, 0.25) # lower bound of interquartile range
25% 
  2 
quantile(data2$health.good, 0.75) # upper bound of interquartile range
75% 
  3