group_id_w1_w2 <- bind_rows(group_id_w1, group_id_w2)

# check if any duplicates, no 
#length(unique(group_id_w1_w2$interact_id))

colnames(group_id_w1_w2) [2] <- "group_id_w1_w2"
##combine van_data_new and van_data_ret

van_data_new$questionnaire <- "New"
van_data_ret$questionnaire <- "Returning"

van_data <- bind_rows(van_data_new, van_data_ret)

van_eli <- bind_rows(van_eli_new, van_eli_ret)

1 Cohort demographics

1.1 Age distribution

summary(van_data$age) %>%
  as.list() %>%
  data.frame() %>%
  knitr::kable(digits = 1, col.names = c("Min", "1st Qu.", "Median", "Mean", "3rd Qu.", "Max")) %>%
  kableExtra::kable_styling("hover", full_width = F)
Min 1st Qu. Median Mean 3rd Qu. Max
19 39 56 54.3 68 87
fillCount = length(unique(van_data$age))
getPalette = colorRampPalette(RColorBrewer::brewer.pal(9, "GnBu"))

ggplot(van_data) +
  geom_histogram(aes(age, y=after_stat(count / sum(count)), fill=factor(age)), binwidth = 5, show.legend = F) +
  theme_light() +
  scale_fill_manual(values = getPalette(fillCount), na.value = "grey") +
  scale_y_continuous(labels = percent) + ylab("")

# Add a age category variable
age_classes <- c("18 - 30", "31 - 50", "51 - 65", "65+")
van_data <- van_data %>%
  mutate(age_class = case_when(age < 31 ~ age_classes[1],
                               age < 51 ~ age_classes[2],
                               age < 66 ~ age_classes[3],
                               TRUE ~ age_classes[4]),
         age_class = factor(age_class, levels = age_classes))

table(van_data$age_class, useNA = "ifany") %>%
  kableExtra::kable(col.names=c('Age categories', 'N')) %>%
  kableExtra::kable_styling("hover", full_width = F)
Age categories N
18 - 30 26
31 - 50 60
51 - 65 74
65+ 66
ggplot(van_data) +
  geom_bar(aes(age_class, y=after_stat(count / sum(count)), fill=age_class), show.legend = FALSE) +
  theme_light() +
  scale_fill_brewer(palette="GnBu", na.value = "grey") +
  scale_y_continuous(labels = percent) + ylab("")

1.2 What is your current gender identity?

gender <- fromJSON('[
        {
          "label": "Man",
          "value": 1
        },
        {
          "label": "Woman",
          "value": 2
        },
        {
          "label": "Trans man",
          "value": 3
        },
        {
          "label": "Trans woman",
          "value": 4
        },
        {
          "label": "Genderqueer/Gender non-conforming",
          "value": 5
        },
        {
          "label": "Different identity",
          "value": 99
        }]') %>%
  mutate(label = factor(label, levels = label))

.ggpdf <- van_data %>%
  left_join(gender, by=c("gender"="value")) %>%
  transmute(interact_id = interact_id,
            gender = label)

# Add gender as factor to dataset (for crosstab below)
van_data <- van_data %>%
  left_join(gender, by=c("gender"="value")) %>%
  mutate(gender_label = label) %>%
  select(!label)

table(.ggpdf$gender, useNA = "ifany") %>%
  kableExtra::kable(col.names=c('Gender', 'N')) %>%
  kableExtra::kable_styling("hover", full_width = F)
Gender N
Man 75
Woman 143
Trans man 0
Trans woman 0
Genderqueer/Gender non-conforming 8
Different identity 0
ggplot(.ggpdf) +
  geom_bar(aes(gender, y=after_stat(count / sum(count)), fill=gender), show.legend = FALSE) +
  theme_light() +
  scale_fill_brewer(palette="GnBu", na.value = "grey") +
  scale_y_continuous(labels = percent) + ylab("")

# grouping gender non-conforming under LGBTQ2S+
gender_groups <- c("Man", "Woman", "Gender minorities")
van_data <- van_data %>%
  mutate(gender_group = case_when(gender == 1 ~ gender_groups[1],
                                  gender == 2 ~ gender_groups[2],
                                  TRUE ~ gender_groups[3]),
         gender_group = factor(gender_group, levels = gender_groups))

1.3 What is your current living arrangement?

NB More than one possible answer

living_arrange <- fromJSON('[
        {
          "label": "Alone?",
          "value": 1
        },
        { 
          "label": "With a spouse (or partner)?",
          "value": 2
        },
        {
          "label": "With children?",
          "value": 3
        },
        {
          "label": "With grandchildren?",
          "value": 4
        },
        {
          "label": "With relatives or siblings?",
          "value": 5
        },
        {
          "label": "With friends?",
          "value": 6
        },
        {
          "label": "With other people?",
          "value": 7
        }
      ]')

.ggpdf <- van_data %>%
  transmute(interact_id = interact_id,
            living_arrange = strsplit(str_sub(living_arrange, 2, -2), ', ')) %>%
  unnest(living_arrange) %>%
  mutate(living_arrange = as.integer(living_arrange)) %>%
  left_join(living_arrange, by=c("living_arrange"="value")) %>%
  transmute(interact_id = interact_id,
            living_arrange = case_when(is.na(living_arrange) ~ 'Living alone',
                                       TRUE ~ str_sub(label, 1, -2)))

table(.ggpdf$living_arrange, useNA = "ifany") %>%
  knitr::kable(col.names=c('Living arrangement', 'N')) %>%
  kableExtra::kable_styling("hover", full_width = F)
Living arrangement N
Alone 64
With a spouse (or partner) 140
With children 58
With friends 10
With grandchildren 1
With other people 7
With relatives or siblings 7
ggplot(.ggpdf) +
  geom_bar(aes(x=living_arrange, y=after_stat(count / sum(count)), fill=living_arrange), show.legend = FALSE) +
  theme_light() +
  theme(axis.text.x=element_text(angle=30,hjust=1)) +
  scale_fill_brewer(palette="GnBu", na.value = "grey") +
  scale_y_continuous(labels=percent) + ylab("")

1.4 Which category best describes your annual household income, taking into account all sources of income?

income <- fromJSON('[
        {
          "label": "No income",
          "value": 1
        },
        {
          "label": "$1 to $9,999",
          "value": 2
        },
        {
          "label": "$10,000 to $14,999",
          "value": 3
        },
        {
          "label": "$15,000 to $19,999",
          "value": 4
        },
        {
          "label": "$20,000 to $29,999",
          "value": 5
        },
        {
          "label": "$30,000 to $39,999",
          "value": 6
        },
        {
          "label": "$40,000 to $49,999",
          "value": 7
        },
        {
          "label": "$50,000 to $99,999",
          "value": 8
        },
        {
          "label": "$100,000 to $149,999",
          "value": 9
        },
        {
          "label": "$150,000 to $199,999",
          "value": 10
        },
        {
          "label": "$200,000 or more",
          "value": 11
        },
        {
          "label": "I don’t know/Prefer not to answer",
          "value": 77
        }
      ]') %>%
  mutate(label = factor(label, levels = label))

.ggpdf <- van_data %>%
  left_join(income, by=c("income"="value")) %>%
  transmute(interact_id = interact_id,
            income = label)

table(.ggpdf$income, useNA = "ifany") %>%
  kableExtra::kable(col.names=c('Income', 'N')) %>%
  kableExtra::kable_styling("hover", full_width = F)
Income N
No income 0
$1 to $9,999 0
$10,000 to $14,999 4
$15,000 to $19,999 7
$20,000 to $29,999 5
$30,000 to $39,999 12
$40,000 to $49,999 9
$50,000 to $99,999 54
$100,000 to $149,999 30
$150,000 to $199,999 32
$200,000 or more 38
I don’t know/Prefer not to answer 35
ggplot(.ggpdf) +
  geom_bar(aes(y=income, x=after_stat(count / sum(count)), fill=income), show.legend = FALSE) +
  theme_light() +
  scale_fill_brewer(palette="GnBu", na.value = "grey") +
  scale_x_continuous(labels=percent) + xlab("")

1.5 What is your highest education level?

education <- fromJSON('[
        {
          "label": "Primary/Elementary school",
          "value": 1
        },
        {
          "label": "Secondary school",
          "value": 2
        },
        {
          "label": "Trade/Technical school or college diploma",
          "value": 3
        },
        {
          "label": "University degree",
          "value": 4
        },
        {
          "label": "Graduate degree",
          "value": 5
        },
        {
          "label": "I don’t know/Prefer not to answer",
          "value": 77
        }
      ]') %>%
  mutate(label = factor(label, levels = label))

.ggpdf <- van_data %>%
  left_join(education, by=c("education"="value")) %>%
  transmute(interact_id = interact_id,
            education = label)

table(.ggpdf$education, useNA = "ifany") %>%
  kableExtra::kable(col.names=c('Education', 'N')) %>%
  kableExtra::kable_styling("hover", full_width = F)
Education N
Primary/Elementary school 0
Secondary school 20
Trade/Technical school or college diploma 23
University degree 88
Graduate degree 93
I don’t know/Prefer not to answer 2
ggplot(.ggpdf) +
  geom_bar(aes(education, y=after_stat(count / sum(count)), fill=education), show.legend = FALSE) +
  theme_light() +
  theme(axis.text.x=element_text(angle=30,hjust=1)) +
  scale_fill_brewer(palette="GnBu", na.value = "grey") +
  scale_x_discrete(labels = scales::label_wrap(25)) +
  scale_y_continuous(labels=percent) + ylab("")

1.6 What is your current employment status?

employment <- fromJSON('[
        {
          "label": "Retired and not working",
          "value": 1
        },
        {
          "label": "Employed full-time",
          "value": 2
        },
        {
          "label": "Employed part-time",
          "value": 3
        },
        {
          "label": "Unemployed and looking for work",
          "value": 4
        },
        {
          "label": "Unemployed and not looking for work",
          "value": 5
        },
        {
          "label": "Other",
          "value": 99
        }
      ]') %>%
  mutate(label = factor(label, levels = label))

.ggpdf <- van_data %>%
  left_join(employment, by=c("employment"="value")) %>%
  transmute(interact_id = interact_id,
            employment = label)

table(.ggpdf$employment, useNA = "ifany") %>%
  kableExtra::kable(col.names=c('Employment', 'N')) %>%
  kableExtra::kable_styling("hover", full_width = F)
Employment N
Retired and not working 61
Employed full-time 92
Employed part-time 45
Unemployed and looking for work 4
Unemployed and not looking for work 6
Other 18
ggplot(.ggpdf) +
  geom_bar(aes(employment, y=after_stat(count / sum(count)), fill=employment), show.legend = FALSE) +
  theme_light() +
  theme(axis.text.x=element_text(angle=30,hjust=1)) +
  scale_fill_brewer(palette="GnBu", na.value = "grey") +
  scale_x_discrete(labels = scales::label_wrap(25)) +
  scale_y_continuous(labels=percent) + ylab("")

1.7 To which ethnic or cultural groups did your ancestors belong?

NB More than one ethnic group possible

ethnicity <- fromJSON('[
        {
          "label": "Aboriginal / Indigenous",
          "value": 1
        },
        {
          "label": "Asian",
          "value": 2
        },
        {
          "label": "Black",
          "value": 3
        },
        {
          "label": "Caucasian",
          "value": 4
        },
        {
          "label": "Latin American",
          "value": 5
        },
        {
          "label": "Middle Eastern",
          "value": 6
        },
        {
          "label": "Other",
          "value": 99
        },
        {
          "label": "I don’t know/Prefer not to answer",
          "value": 77
        }
      ]') %>%
  mutate(label = factor(label, levels = label))

.ggpdf <- van_data %>%
  left_join(group_id_w1_w2, by="interact_id") %>%
  transmute(interact_id = interact_id,
            group_id = coalesce(group_id, group_id_w1_w2)) %>%
  transmute(interact_id = interact_id,
           group_id = strsplit(str_sub(group_id, 2, -2), ', ')) %>%
  unnest(group_id) %>%
  mutate(group_id = as.integer(group_id)) %>%
  left_join(ethnicity, by=c("group_id"="value")) %>%
  transmute(interact_id = interact_id,
            ethnicity = label) %>%
  filter(!is.na(ethnicity))


table(.ggpdf$ethnicity, useNA = "ifany") %>%
  kableExtra::kable(col.names=c('Ethnicity', 'N')) %>%
  kableExtra::kable_styling("hover", full_width = F)
Ethnicity N
Aboriginal / Indigenous 4
Asian 18
Black 0
Caucasian 190
Latin American 7
Middle Eastern 3
Other 0
I don’t know/Prefer not to answer 3
ggplot(.ggpdf) +
  geom_bar(aes(ethnicity, y=after_stat(count / sum(count)), fill=ethnicity), show.legend = FALSE) +
  theme_light() +
  theme(axis.text.x=element_text(angle=30,hjust=1)) +
  scale_fill_brewer(palette="GnBu", na.value = "grey") +
  scale_x_discrete(labels = scales::label_wrap(20))+
  scale_y_continuous(labels=percent) + ylab("")

1.8 Housing tenure

house_tenure <- fromJSON('[
        {
          "label": "An owner",
          "value": 1
        },
        {
          "label": "A tenant",
          "value": 2
        },
        {
          "label": "A resident in a relative or friend’s home",
          "value": 3
        },
        {
          "label": "A resident other than in a relative or friend’s home",
          "value": 4
        },
        {
          "label": "Other",
          "value": 99
        },
        {
          "label": "I don’t know/Prefer not to answer",
          "value": 77
        }
      ]') %>%
  mutate(label = factor(label, levels = label))


## rename -7 to NA
van_data$house_tenure <- replace(van_data$house_tenure, van_data$house_tenure < 0, NA)



.ggpdf <- van_data %>%
  left_join(van_data_w2w1, by="interact_id") %>%
  transmute(interact_id = interact_id,
            house_tenure = coalesce(house_tenure, house_tenure_w2, house_tenure_w1)) %>%
  left_join(house_tenure, by=c("house_tenure"="value")) %>%
  transmute(interact_id = interact_id,
            house_tenure = label) %>%
  filter(!is.na(house_tenure))

table(.ggpdf$house_tenure, useNA = "ifany") %>%
  kableExtra::kable(col.names=c('Housing tenure', 'N')) %>%
  kableExtra::kable_styling("hover", full_width = F)
Housing tenure N
An owner 136
A tenant 67
A resident in a relative or friend’s home 7
A resident other than in a relative or friend’s home 1
Other 7
I don’t know/Prefer not to answer 0
ggplot(.ggpdf) +
  geom_bar(aes(house_tenure, y=after_stat(count / sum(count)), fill=house_tenure), show.legend = FALSE) +
  theme_light() +
  theme(axis.text.x=element_text(angle=30,hjust=1)) +
  scale_fill_brewer(palette="GnBu", na.value = "grey") +
  scale_x_discrete(labels = scales::label_wrap(25))+
  scale_y_continuous(labels=percent) + ylab("")

1.9 Dwelling

dwelling_type <- fromJSON('[
        {
          "label": "A single-detached house",
          "value": 1
        },
        {
          "label": "A semi-detached house",
          "value": 2
        },
        {
          "label": "A row house",
          "value": 3
        },
        {
          "label": "An apartment (or condo) in a duplex or triplex (two or three dwellings located one above the other)",
          "value": 4
        },
        {
          "label": "An apartment (or condo) in a building that has fewer than five storeys",
          "value": 5
        },
        {
          "label": "An apartment (or condo) in a building that has five or more storeys",
          "value": 6
        },
        {
          "label": "A mobile home or other movable dwelling",
          "value": 7
        },
        {
          "label": "A seniors’ home",
          "value": 8
        },
        {
          "label": "Other",
          "value": 99
        },
        {
          "label": "I don’t know/Prefer not to answer",
          "value": 77
        }
      ]') %>%
  mutate(label = factor(label, levels = label))


## rename -7 to NA
van_data$dwelling_type <- replace(van_data$dwelling_type, van_data$dwelling_type < 0, NA)

.ggpdf <- van_data %>%
  left_join(van_data_w2w1, by="interact_id") %>%
  transmute(interact_id = interact_id,
            dwelling_type = coalesce(dwelling_type, dwelling_type_w2, dwelling_type_w1)) %>%
  left_join(dwelling_type, by=c("dwelling_type"="value")) %>%
  transmute(interact_id = interact_id,
            dwelling_type = label)%>%
 filter(!is.na(dwelling_type))

table(.ggpdf$dwelling_type, useNA = "ifany") %>%
  kableExtra::kable(col.names=c('Dwelling', 'N')) %>%
  kableExtra::kable_styling("hover", full_width = F)
Dwelling N
A single-detached house 69
A semi-detached house 12
A row house 14
An apartment (or condo) in a duplex or triplex (two or three dwellings located one above the other) 13
An apartment (or condo) in a building that has fewer than five storeys 66
An apartment (or condo) in a building that has five or more storeys 36
A mobile home or other movable dwelling 0
A seniors’ home 0
Other 7
I don’t know/Prefer not to answer 1
ggplot(.ggpdf) +
  geom_bar(aes(y=dwelling_type, x=after_stat(count / sum(count)), fill=dwelling_type), show.legend = FALSE) +
  theme_light() +
  #theme(axis.text.x=element_text(angle=30,hjust=1)) +
  scale_fill_brewer(palette="GnBu", na.value = "grey") +
  scale_y_discrete(label=label_wrap(50))+
  scale_x_continuous(labels=percent) + xlab("")

1.10 Returning or new participant

van_data %>%
  count(questionnaire) %>%
  kableExtra::kable() %>%
  kableExtra::kable_styling("hover", full_width = F)
questionnaire n
New 55
Returning 171
ggplot(van_data) +
  geom_bar(aes(questionnaire, y=after_stat(count / sum(count)), fill=questionnaire), show.legend = FALSE) +
  theme_light() +
  #theme(axis.text.x=element_text(angle=30,hjust=1)) +
  scale_fill_brewer(palette="GnBu", na.value = "grey")+
  scale_y_continuous(labels=percent) + ylab("")

2 Usage (all city greenways)

2.1 Whether participant has used intervention (ie. a city greenway)

Does participant uses any of the 10 greenways?

2.1.1 Global

use <- fromJSON('[
        {
          "label": "Yes",
          "value": 1
        },
        {
          "label": "No",
          "value": 2
        }
      ]') %>%
  mutate(label = factor(label, levels = label))

.ggpdf <- van_data %>%
  select(interact_id, starts_with("greenway_use")) %>%
  select(!starts_with("greenway_use_other")) %>%
  pivot_longer(starts_with("greenway_use"), names_to = "greenway", names_prefix = "greenway_use_", values_to = "use") %>%
  group_by(interact_id) %>%
  summarise(use_any = min(use)) %>%
  left_join(use, by=c("use_any" = "value")) %>%
  transmute(interact_id = interact_id,
            used_intervention = label)

# Join back newly created variable
van_data <- van_data %>%
  left_join(.ggpdf, by = c("interact_id" = "interact_id"))

table(.ggpdf$used_intervention) %>%
  knitr::kable(col.names = c("Use", "N")) %>%
  kableExtra::kable_styling("hover", full_width = F)
Use N
Yes 213
No 13
ggplot(.ggpdf) +
  geom_bar(aes(used_intervention, y=after_stat(count / sum(count)), fill=used_intervention), show.legend = FALSE) +
  theme_light() +
  scale_fill_brewer(palette="GnBu", na.value = "grey")+
  scale_y_continuous(labels=percent) + ylab("")

2.1.2 By age

# Used_intervention already added
rbind(table(pull(filter(van_data, age_class == age_classes[1]), used_intervention)),
      table(pull(filter(van_data, age_class == age_classes[2]), used_intervention)),
      table(pull(filter(van_data, age_class == age_classes[3]), used_intervention)),
      table(pull(filter(van_data, age_class == age_classes[4]), used_intervention))) %>%
  t() %>%
  kableExtra::kable(col.names = age_classes) %>%
  kableExtra::kable_styling("hover", full_width = F)
18 - 30 31 - 50 51 - 65 65+
Yes 26 57 69 61
No 0 3 5 5
.ggpdf_pct <- van_data %>% 
  group_by(age_class, used_intervention) %>%
  summarise(n = n()) %>%
  inner_join(count(van_data, age_class), by = "age_class", suffix = c("", ".tot")) %>%
  mutate(percent = n / n.tot) %>%
  select(!n) 

ggplot(.ggpdf_pct) +
  geom_bar(aes(x = used_intervention, y = percent, fill=used_intervention), stat = "identity", show.legend = FALSE) +
  theme_light() +
  scale_fill_brewer(palette="GnBu", na.value = "grey") +
  scale_y_continuous(labels=percent) + ylab("percent with each age group") +
  facet_wrap(vars(age_class), ncol = 2)