1
$\begingroup$

I'm analyzing behaviour's persons in transportation and have the following data :

I'm wondering to verify the following hypothesis : Individual will look to confort (Type:no=0,yes=1) proportionnaly if their duration's journey is more important and if their age is more important.

I've the following plot enter image description here

Visually, Ii seems that datas follows this hypothesis, but how to verify it statistically ? which type of test to use ?

df=structure(list(Type = c("0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "1", "0", "0", "0", "0", "0", 
"0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "1", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"1", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "1", "0", "0", "0", "0", "0", "0", "0", "1", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "0", 
"1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "1", "1", "0", "0", "0", "0", "0", "0", "1", 
"1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"1", "0", "0", "1", "0", "0", "0", "1", "0", "0", "0", "0", "0", 
"0", "1", "1", "0", "1", "1", "0", "0", "0", "0", "0", "0", "0", 
"0", "1", "0", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", 
"1", "0", "0", "0", "0", "1", "1", "1", "1", "0", "0", "1", "0", 
"0", "0", "0", "0", "0", "0", "1", "1", "0", "1", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "1", "0", "0", "1", "0", "0", "0", 
"0", "0", "0", "0", "1", "0", "0", "0", "1", "0", "1", "0", "0", 
"1", "0", "0", "0", "1", "1", "0", "0", "0", "0", "0", "0", "0", 
"1", "0", "1", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", 
"1", "1", "0"), Times = c(9L, 25L, 23L, 50L, 9L, 4L, 20L, 36L, 
25L, 28L, 32L, 26L, 26L, 26L, 26L, 4L, 16L, 9L, 25L, 26L, 28L, 
32L, 4L, 6L, 6L, 6L, 6L, 6L, 4L, 44L, 15L, 9L, 4L, 4L, 9L, 6L, 
26L, 33L, 44L, 44L, 4L, 36L, 14L, 4L, 4L, 36L, 9L, 32L, 32L, 
4L, 44L, 26L, 9L, 6L, 4L, 33L, 26L, 26L, 26L, 23L, 26L, 9L, 14L, 
36L, 44L, 4L, 35L, 32L, 28L, 28L, 9L, 6L, 4L, 36L, 26L, 9L, 9L, 
9L, 4L, 4L, 14L, 33L, 15L, 4L, 4L, 58L, 26L, 4L, 33L, 9L, 4L, 
4L, 4L, 39L, 26L, 9L, 6L, 33L, 28L, 33L, 20L, 33L, 6L, 14L, 20L, 
50L, 58L, 17L, 36L, 28L, 33L, 50L, 16L, 4L, 33L, 50L, 9L, 26L, 
28L, 4L, 58L, 9L, 17L, 6L, 14L, 58L, 28L, 9L, 6L, 50L, 9L, 9L, 
9L, 4L, 26L, 9L, 9L, 14L, 36L, 44L, 20L, 26L, 50L, 6L, 9L, 16L, 
14L, 11L, 44L, 9L, 58L, 9L, 14L, 9L, 36L, 28L, 17L, 28L, 23L, 
11L, 33L, 6L, 14L, 36L, 9L, 9L, 11L, 17L, 17L, 20L, 9L, 14L, 
11L, 20L, 6L, 4L, 9L, 14L, 11L, 4L, 6L, 14L, 23L, 36L, 23L, 20L, 
11L, 9L, 9L, 14L, 26L, 9L, 6L, 16L, 18L, 23L, 43L, 23L, 6L, 6L, 
9L, 28L, 20L, 58L, 36L, 11L, 51L, 20L, 26L, 33L, 9L, 6L, 9L, 
17L, 14L, 58L, 11L, 20L, 6L, 17L, 14L, 28L, 16L, 6L, 6L, 28L, 
6L, 6L, 9L, 28L, 9L, 22L, 14L, 6L, 6L, 14L, 17L, 36L, 37L, 20L, 
20L, 35L, 23L, 9L, 25L, 23L, 23L, 33L, 18L, 51L, 9L, 6L, 6L, 
9L, 17L, 9L, 29L, 28L, 20L, 28L, 14L, 50L, 14L, 17L, 6L, 11L, 
11L, 28L, 20L, 28L, 20L, 6L, 6L, 9L, 9L, 47L, 9L, 9L, 11L, 17L, 
23L, 23L, 44L, 20L, 36L, 52L, 17L, 17L, 44L, 28L, 11L, 14L, 28L, 
23L, 9L, 9L, 17L, 18L, 22L, 28L, 9L, 14L, 14L, 14L, 23L, 23L, 
52L, 17L, 28L, 14L, 28L, 9L, 6L, 6L, 28L, 23L, 23L, 4L, 37L, 
51L, 51L, 14L, 23L, 6L, 28L, 20L, 17L, 26L, 11L, 35L, 15L, 14L, 
20L, 18L, 4L, 29L, 6L, 30L, 51L, 23L, 9L, 23L, 14L, 23L, 14L, 
15L, 36L, 9L, 37L, 29L, 28L, 30L, 23L, 51L, 51L, 17L, 17L, 30L, 
18L, 23L, 28L, 15L, 14L, 9L, 28L, 33L, 14L, 23L, 9L, 14L, 26L, 
9L, 23L, 14L, 9L, 44L, 43L, 15L, 4L, 14L, 14L, 23L, 52L, 23L, 
14L, 32L, 17L, 17L, 44L, 20L, 30L, 28L, 43L, 33L, 23L, 9L, 44L, 
33L, 23L, 18L, 26L, 26L, 26L, 9L, 6L, 11L, 6L, 18L, 30L, 51L, 
44L, 23L, 43L, 30L, 23L, 17L, 44L, 43L, 23L, 15L, 28L, 17L, 18L, 
23L, 26L, 14L, 9L, 28L, 15L, 16L, 9L, 17L, 30L, 15L, 20L, 6L, 
23L, 18L, 32L, 30L, 18L, 17L, 23L, 18L, 18L, 6L, 17L, 30L, 51L, 
44L, 23L, 28L, 18L, 15L, 18L, 28L, 26L, 44L, 23L, 23L, 17L, 28L, 
30L, 17L, 44L, 43L, 30L, 38L, 17L, 28L, 26L, 17L, 17L, 18L, 23L, 
28L, 6L, 30L, 17L, 9L, 28L, 28L, 28L, 11L, 17L, 17L, 20L, 9L, 
30L, 18L, 47L, 30L, 23L, 33L, 18L, 30L, 17L, 36L, 30L, 23L, 17L, 
30L, 33L, 14L, 18L, 15L, 32L, 23L, 23L, 30L, 23L, 30L, 30L, 43L, 
30L, 30L, 17L, 36L, 17L, 17L, 51L, 30L, 17L, 15L, 50L, 11L, 11L, 
4L, 32L, 26L, 17L), Age = c(27L, 38L, 16L, 50L, 30L, 26L, 65L, 
28L, 25L, 57L, 26L, 53L, 26L, 21L, 21L, 25L, 55L, 16L, 59L, 22L, 
45L, 19L, 40L, 10L, 54L, 51L, 30L, 20L, 22L, 22L, 37L, 39L, 50L, 
35L, 20L, 44L, 26L, 32L, 20L, 26L, 56L, 36L, 31L, 30L, 38L, 58L, 
40L, 58L, 53L, 34L, 48L, 55L, 27L, 48L, 47L, 16L, 29L, 45L, 19L, 
49L, 48L, 34L, 26L, 52L, 39L, 30L, 39L, 21L, 19L, 34L, 39L, 63L, 
21L, 43L, 50L, 25L, 54L, 55L, 42L, 43L, 29L, 26L, 43L, 37L, 25L, 
31L, 21L, 23L, 30L, 30L, 55L, 18L, 45L, 28L, 51L, 43L, 15L, 18L, 
39L, 52L, 52L, 36L, 20L, 52L, 64L, 52L, 42L, 45L, 17L, 19L, 60L, 
55L, 48L, 67L, 58L, 26L, 34L, 56L, 62L, 36L, 32L, 51L, 30L, 54L, 
56L, 60L, 49L, 50L, 40L, 51L, 28L, 59L, 35L, 20L, 53L, 35L, 54L, 
27L, 22L, 46L, 33L, 33L, 41L, 34L, 39L, 46L, 58L, 25L, 58L, 33L, 
28L, 39L, 22L, 25L, 59L, 49L, 50L, 46L, 54L, 37L, 20L, 50L, 22L, 
32L, 30L, 25L, 25L, 60L, 26L, 55L, 44L, 53L, 19L, 29L, 36L, 28L, 
54L, 56L, 48L, 35L, 39L, 28L, 37L, 41L, 22L, 54L, 50L, 57L, 56L, 
40L, 22L, 34L, 21L, 14L, 35L, 65L, 54L, 42L, 38L, 14L, 28L, 55L, 
64L, 46L, 37L, 39L, 45L, 42L, 20L, 20L, 35L, 17L, 46L, 20L, 19L, 
45L, 55L, 28L, 33L, 45L, 52L, 42L, 30L, 37L, 33L, 18L, 56L, 36L, 
60L, 50L, 47L, 27L, 22L, 25L, 19L, 51L, 24L, 55L, 32L, 60L, 19L, 
50L, 44L, 41L, 46L, 28L, 56L, 25L, 51L, 30L, 32L, 19L, 37L, 39L, 
60L, 18L, 28L, 45L, 58L, 29L, 22L, 50L, 17L, 33L, 26L, 28L, 31L, 
23L, 49L, 52L, 22L, 30L, 37L, 33L, 32L, 33L, 22L, 27L, 37L, 17L, 
24L, 30L, 40L, 18L, 54L, 49L, 41L, 47L, 44L, 53L, 48L, 40L, 20L, 
21L, 54L, 23L, 22L, 31L, 41L, 47L, 36L, 22L, 51L, 27L, 30L, 50L, 
56L, 44L, 38L, 43L, 54L, 52L, 42L, 59L, 43L, 38L, 57L, 20L, 50L, 
25L, 25L, 25L, 30L, 39L, 33L, 50L, 39L, 49L, 53L, 57L, 74L, 48L, 
35L, 51L, 53L, 41L, 27L, 18L, 28L, 30L, 33L, 59L, 25L, 39L, 37L, 
52L, 47L, 56L, 30L, 53L, 64L, 47L, 55L, 50L, 55L, 47L, 45L, 56L, 
26L, 27L, 31L, 28L, 39L, 61L, 50L, 54L, 22L, 54L, 40L, 40L, 44L, 
40L, 31L, 55L, 38L, 51L, 28L, 35L, 33L, 25L, 41L, 35L, 53L, 29L, 
27L, 33L, 35L, 39L, 47L, 42L, 20L, 34L, 56L, 41L, 55L, 53L, 53L, 
25L, 56L, 57L, 53L, 18L, 57L, 58L, 57L, 38L, 44L, 22L, 50L, 59L, 
47L, 50L, 44L, 50L, 43L, 24L, 45L, 53L, 52L, 18L, 45L, 27L, 30L, 
55L, 31L, 39L, 50L, 45L, 45L, 50L, 43L, 39L, 48L, 22L, 39L, 41L, 
34L, 52L, 53L, 53L, 31L, 35L, 62L, 53L, 60L, 41L, 30L, 23L, 42L, 
56L, 43L, 35L, 56L, 34L, 56L, 38L, 41L, 52L, 62L, 30L, 51L, 44L, 
54L, 24L, 53L, 47L, 42L, 43L, 57L, 18L, 62L, 40L, 37L, 36L, 52L, 
41L, 42L, 48L, 41L, 33L, 26L, 43L, 37L, 33L, 26L, 32L, 42L, 31L, 
18L, 26L, 20L, 43L, 35L, 33L, 38L, 50L, 37L, 42L, 35L, 52L, 43L, 
35L, 50L, 37L, 30L, 49L, 46L, 54L, 29L, 38L, 54L, 27L, 57L, 52L, 
26L, 23L, 36L, 56L, 38L, 50L, 59L, 19L, 42L, 18L, 22L, 22L, 22L, 
24L, 23L, 37L, 40L)), .Names = c("Type", "Times", "Age"), row.names = c(NA, 
-531L), class = "data.frame")

EDIT 1: Reshaping data with 'withTrainStrat' (looking for comfort) 'noTrainStrat'(not looking for comfort)

        res=structure(list(Age = structure(c(1L, 1L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 
7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 
11L, 11L, 11L, 11L, 11L, 11L, 12L, 13L, NA), .Label = c("(10,15]", 
"(15,20]", "(20,25]", "(25,30]", "(30,35]", "(35,40]", "(40,45]", 
"(45,50]", "(50,55]", "(55,60]", "(60,65]", "(65,70]", "(70,75]", 
"(75,80]"), class = "factor"), Time = c(6L, 16L, 4L, 6L, 9L, 
11L, 14L, 15L, 17L, 20L, 23L, 26L, 28L, 30L, 32L, 33L, 36L, 44L, 
47L, 4L, 6L, 9L, 11L, 14L, 15L, 17L, 18L, 20L, 23L, 25L, 26L, 
28L, 30L, 32L, 33L, 36L, 44L, 50L, 51L, 4L, 6L, 9L, 11L, 14L, 
15L, 16L, 17L, 18L, 20L, 22L, 23L, 26L, 28L, 29L, 30L, 32L, 33L, 
36L, 37L, 39L, 43L, 44L, 50L, 51L, 58L, 4L, 6L, 9L, 11L, 14L, 
15L, 17L, 18L, 20L, 23L, 26L, 28L, 30L, 32L, 33L, 36L, 37L, 47L, 
58L, 4L, 6L, 9L, 11L, 14L, 15L, 17L, 18L, 20L, 23L, 25L, 26L, 
28L, 30L, 33L, 35L, 36L, 44L, 4L, 6L, 9L, 14L, 15L, 17L, 20L, 
22L, 23L, 25L, 26L, 28L, 29L, 30L, 33L, 36L, 38L, 43L, 44L, 50L, 
51L, 58L, 4L, 6L, 9L, 11L, 14L, 15L, 16L, 17L, 20L, 23L, 25L, 
26L, 28L, 30L, 32L, 33L, 35L, 36L, 37L, 43L, 44L, 50L, 51L, 52L, 
58L, 4L, 6L, 9L, 11L, 14L, 15L, 16L, 17L, 18L, 20L, 23L, 26L, 
28L, 29L, 30L, 32L, 33L, 36L, 43L, 44L, 50L, 51L, 52L, 4L, 6L, 
9L, 14L, 17L, 18L, 20L, 23L, 25L, 26L, 28L, 30L, 32L, 33L, 35L, 
36L, 43L, 44L, 51L, 52L, 58L, 6L, 9L, 20L, 23L, 26L, 28L, 36L, 
4L, 15L, 6L), withTrainStrat = c(2L, 1L, 4L, 5L, 2L, 1L, 2L, 
2L, 2L, 2L, 1L, 3L, 4L, 4L, 1L, 4L, 1L, 1L, 1L, 6L, 2L, 4L, 4L, 
8L, 1L, 4L, 1L, 1L, 3L, 1L, 5L, 1L, 1L, 0L, 2L, 1L, 1L, 1L, 2L, 
4L, 4L, 8L, 2L, 6L, 1L, 1L, 4L, 4L, 2L, 1L, 9L, 3L, 3L, 1L, 2L, 
1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 4L, 3L, 13L, 2L, 1L, 
2L, 4L, 3L, 2L, 3L, 2L, 5L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 4L, 9L, 
9L, 4L, 5L, 1L, 8L, 2L, 1L, 3L, 1L, 0L, 3L, 1L, 1L, 1L, 2L, 2L, 
3L, 7L, 3L, 2L, 1L, 7L, 3L, 1L, 1L, 1L, 3L, 8L, 1L, 2L, 1L, 3L, 
1L, 1L, 2L, 1L, 2L, 2L, 2L, 3L, 2L, 3L, 2L, 1L, 2L, 3L, 2L, 2L, 
1L, 3L, 3L, 6L, 0L, 0L, 1L, 0L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 2L, 
3L, 8L, 2L, 6L, 1L, 1L, 1L, 3L, 3L, 7L, 5L, 4L, 1L, 2L, 1L, 2L, 
3L, 3L, 3L, 3L, 1L, 0L, 1L, 3L, 6L, 3L, 3L, 4L, 2L, 3L, 1L, 2L, 
1L, 2L, 1L, 2L, 0L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 0L, 3L, 2L, 0L, 
2L, 1L, 1L, 1L, 1L), noTrainStrat = c(0L, 0L, 0L, 0L, 1L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 
0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 2L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 
1L, 0L, 2L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 2L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 3L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 
0L, 0L, 3L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 3L, 0L, 0L, 0L, 0L, 1L, 0L, 
0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 
0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 
0L, 0L, 0L, 0L, 0L)), class = "data.frame", row.names = c(NA, 
-203L), .Names = c("Age", "Time", "withTrainStrat", "noTrainStrat"
))

I tried glm :

attach(res)
    glm(cbind(withTrainStrat,noTrainStrat) ~ Age + Time , family=binomial)
    Call:  glm(formula = cbind(withTrainStrat, noTrainStrat) ~ Age + Time, 
    family = binomial)

Coefficients:
(Intercept)   Age(15,20]   Age(20,25]   Age(25,30]   Age(30,35]   Age(35,40]   Age(40,45]   Age(45,50]   Age(50,55]   Age(55,60]   Age(60,65]   Age(65,70]  
   16.92263    -13.58371    -14.31765    -12.32297    -13.72855    -14.55698    -14.70179    -15.26747    -14.29382    -13.85213    -15.47425     -0.29318  
 Age(70,75]         Time  
   -0.11887     -0.01585  

Degrees of Freedom: 201 Total (i.e. Null);  188 Residual
  (1 observation deleted due to missingness)
Null Deviance:      177 
Residual Deviance: 150.7        AIC: 238.9

Is it the correct way to analyze my data? I think my results are not signitificant :

    > 1-pchisq(150.7,188)
[1] 0.9789707
$\endgroup$
  • $\begingroup$ You probably have you pchisq upside down. I extended my answer to show you how such an analysis can be done. Hope it is still in time for you. $\endgroup$ – Maarten Punt Jan 20 '18 at 22:05
1
$\begingroup$

In principle as a first indication you could do a t-test comparing e.g. the mean age of those that opt for the comfortable option with the mean age of those that do not. This will tell you whether the average traveller in the comfortable option is older than the one in the uncomfortable one. A similar procedure can be followed for journey time. Incidentally I prefer boxplots to visualize these individual differences.

There is, however, a bit of a problem with that approach because it doesn't account for the effects simultaneously (which seems to be what your after). Suppose that the people that are older are also mostly the ones that travel longer, then the reason why you find a difference in say the t-test for age might well be that older people are also the ones with more travel time.

Fron the question I gather you want to estimate whether the probability of selecting a comfortable option increases with age and journey time. You can do so with binary choice models where you model how the probability of selecting one option changes with other variables. That would allow you to account for the effect of age and journey time simultaneously. The two basic approaches in that field are called logit and probit. Although more advanced this will give you a more complete picture.

There is no need to reshape your data, in the code below I analysed your original dataframe, which I find simpler.

#Replace your "type"character variable with a numeric one (you could use a factors if you wanted to)
df$Type <- as.numeric(df$Type)
#Create a first model
model1 <- glm(Type~Times+Age, data = df, family = binomial())
#Create a "null model" with only an intercept to test it against
model2 <- glm(Type~1, data = df, family = binomial())
anova(model2, model1, test = "LRT")
Analysis of Deviance Table

Model 1: Type ~ 1
Model 2: Type ~ Times + Age
  Resid. Df Resid. Dev Df Deviance Pr(>Chi)  
1       530     344.80                       
2       528     336.97  2   7.8274  0.01997 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Using a likelihood ratio test you see that your model as a whole is significant. Now let's look at the model and its coefficients

summary(model1)

Call:
glm(formula = Type ~ Times + Age, family = binomial(), data = df)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-0.7409  -0.4999  -0.4177  -0.3628   2.4482  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept) -3.59004    0.55446  -6.475 9.49e-11 ***
Times        0.01626    0.01081   1.503   0.1327    
Age          0.02491    0.01166   2.136   0.0327 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 344.80  on 530  degrees of freedom
Residual deviance: 336.97  on 528  degrees of freedom
AIC: 342.97

Number of Fisher Scoring iterations: 5

Ok so only age is significant. Given that this is a logit model we cannot interpret the coefficients directly but we only see that the probability of taking transport type 1 increases with age.

If you want some more meaning you can calculate the odds ratio:

exp(model1$coefficients)
(Intercept)       Times         Age 
0.0275972   1.0163903   1.0252242 

The odds (NOT the probability) of taking transport type 1 are multiplied with 1.02 for each additional year of age.

Or calculate the marginal effect. I typically use the mfx package for that:

require(mfx)
logitmfx( Type~Times+Age, data = df)
Call:
logitmfx(formula = Type ~ Times + Age, data = df)

Marginal Effects:
           dF/dx  Std. Err.      z   P>|z|  
Times 0.00138519 0.00091086 1.5208 0.12832  
Age   0.00212254 0.00096313 2.2038 0.02754 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

At the mean time and age in the dataset, an additional year of age increases the probability of taking type 1 transport with 0.002. Significant, but not a terribly large effect.

If you use ggplot you can visualize your results as well.

#Create a new dataframe with Times set at the mean    
df2 <- df
df2$Times <- mean(df$Times)
#Build a visualization with a model based on age only
ggplot(data = df2)+aes(x=Age, y=Type)+geom_point()+geom_smooth(method = "glm",method.args =list(family=binomial()))

Which gives you this:enter image description here

Finally, if you want to read up on these things there are many resources around the web, with varying degrees of technicality, such as these:

https://www.youtube.com/watch?v=EocjYP5h0cE

https://www.youtube.com/watch?v=1cFYlMjEz-c

https://www.youtube.com/watch?v=A9P888Lxde8

More examples and tests can a.o. be found here:

http://www.ats.ucla.edu/stat/r/dae/logit.htm

$\endgroup$
  • $\begingroup$ Thanks a lot for these suggestions. I followed your advice, please look on the EDIT 1. Is it the correct way, and how to interpret these results ? $\endgroup$ – ranell Jan 17 '18 at 14:27
  • $\begingroup$ it's wonderful , Thanks you very much for this rich reply ! $\endgroup$ – ranell Jan 28 '18 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.