This assignment is divided into three main sections.
In the first section, you will select two Census Tracts within Fulton and DeKalb Counties, GA — one that you believe is the most walkable and another that is the least walkable. You may choose any tracts within these two counties. If the area you want to analyze is not well represented by a single tract, you may select multiple adjacent tracts (e.g., two contiguous tracts as one “walkable area”). The definition of walkable is up to you — it can be based on your personal experience (e.g., places where you’ve had particularly good or bad walking experiences), Walk Score data, or any combination of criteria. After making your selections, provide a brief explanation of why you chose those tracts.
The second section is the core of this assignment. You will prepare OpenStreetMap (OSM) data, download Google Street View (GSV) images, and apply the computer vision technique covered in class — semantic segmentation.
In the third section, you will summarize and analyze the results. After applying computer vision to the images, you will obtain pixel counts for 19 different object categories. Using the data, you will:
Importing the necessary packages is part of this assignment. Add any required packages to the code chunk below as you progress through the tasks.
library(tmap)
library(here)
## here() starts at C:/Users/SHAMBHAVI SINHA/OneDrive/semester1_mcrp/urban_analytics_R/urban_analytics
library(osmdata)
## Warning: package 'osmdata' was built under R version 4.5.2
## Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
library(sfnetworks)
## Warning: package 'sfnetworks' was built under R version 4.5.2
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 4.0.0 ✔ tibble 3.3.0
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.1.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(magrittr)
##
## Attaching package: 'magrittr'
##
## The following object is masked from 'package:purrr':
##
## set_names
##
## The following object is masked from 'package:tidyr':
##
## extract
library(sf)
## Linking to GEOS 3.13.1, GDAL 3.11.0, PROJ 9.6.0; sf_use_s2() is TRUE
library(units)
## udunits database from C:/Users/SHAMBHAVI SINHA/AppData/Local/R/win-library/4.5/units/share/udunits/udunits2.xml
library(tidygraph)
## Warning: package 'tidygraph' was built under R version 4.5.2
##
## Attaching package: 'tidygraph'
##
## The following object is masked from 'package:stats':
##
## filter
library(progress)
library(nominatimlite)
## Warning: package 'nominatimlite' was built under R version 4.5.2
library(sfnetworks)
library(geosphere)
## Warning: package 'geosphere' was built under R version 4.5.2
library(fs)
library(tidycensus)
ttm()
## ℹ tmap mode set to "view".
## ℹ switch back to "plot" mode with `tmap::ttm()`
Use the Census Tract map in the following code chunk to identify the GEOIDs of the tracts you consider walkable and unwalkable.
# TASK ////////////////////////////////////////////////////////////////////////
# Set up your api key here
census_api_key (Sys.getenv("Census_API"))
## To install your API key for use in future sessions, run this function with `install = TRUE`.
# //TASK //////////////////////////////////////////////////////////////////////
# =========== NO MODIFICATION ZONE STARTS HERE ===============================
# Download Census Tract polygon for Fulton and DeKalb
tract <- get_acs("tract",
variables = c('pop' = 'B01001_001'),
year = 2023,
state = "GA",
county = c("Fulton", "DeKalb"),
geometry = TRUE)
## Getting data from the 2019-2023 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Downloading: 4.1 kB Downloading: 4.1 kB Downloading: 6.6 kB Downloading: 6.6 kB Downloading: 6.6 kB Downloading: 6.6 kB
tmap_mode("view")
## ℹ tmap mode set to "view".
tm_basemap("OpenStreetMap") +
tm_shape(tract) +
tm_polygons(fill_alpha = 0.2)
## Registered S3 method overwritten by 'jsonify':
## method from
## print.json jsonlite
# =========== NO MODIFY ZONE ENDS HERE ========================================
Once you have the GEOIDs, create two Census Tract objects – one representing your most walkable area and the other your least walkable area.
# TASK ////////////////////////////////////////////////////////////////////////
# 1. Specify the GEOIDs of your walkable and unwalkable Census Tracts.
# e.g., tr_id_walkable <- c("13121001205", "13121001206")
# 2. Extract the selected Census Tracts using `tr_id_walkable` and `tr_id_unwalkable`
# For the walkable Census Tract(s)
tr_id_walkable <- c("13089021411", "13121011901")
tract_walkable <- tract %>%
dplyr::filter(GEOID %in% tr_id_walkable)
# For the unwalkable Census Tract(s)
tr_id_unwalkable <- c("13121010601", "13089022203")
tract_unwalkable <- tract %>%
dplyr::filter(GEOID %in% tr_id_unwalkable)
# //TASK //////////////////////////////////////////////////////////////////////
# TASK ////////////////////////////////////////////////////////////////////////
# Create an interactive map showing `tract_walkable` and `tract_unwalkable`
tm_shape(tract_walkable) +
tm_polygons(col = "green", alpha = 0.5, legend.show = FALSE) +
tm_shape(tract_unwalkable) +
tm_polygons(col = "red", alpha = 0.5, legend.show = FALSE) +
tm_view()
##
## ── tmap v3 code detected ───────────────────────────────────────────────────────
## [v3->v4] `tm_polygons()`: use 'fill' for the fill color of polygons/symbols
## (instead of 'col'), and 'col' for the outlines (instead of 'border.col').
## [v3->v4] `tm_polygons()`: use `fill_alpha` instead of `alpha`.
## [v3->v4] `tm_polygons()`: use `fill.legend = tm_legend_hide()` instead of
## `legend.show = FALSE`.
## [v3->v4] `tm_polygons()`: use `fill_alpha` instead of `alpha`.
## [v3->v4] `tm_polygons()`: use `fill.legend = tm_legend_hide()` instead of
## `legend.show = FALSE`.
## This message is displayed once every 8 hours.
# //TASK //////////////////////////////////////////////////////////////////////
Provide a brief description of your selected Census Tracts. Why do you consider these tracts walkable or unwalkable? What factors do you think contribute to their walkability?
The central area of the metropolitan Atlanta and the areas around have high walkablity score as extracted through the isual presentation on the site. While the non-walkable tracts increase as the distance from the city center increases also seen by the selection of the tracts.
To obtain the OSM network for your selected Census Tracts: (1) Create
bounding boxes. (2) Use the bounding boxes to download OSM data. (3)
Convert the data into an sfnetwork object and clean it.
# TASK ////////////////////////////////////////////////////////////////////////
# Create one bounding box (`tract_walkable_bb`) for your walkable Census Tract(s) and another (`tract_unwalkable_bb`) for your unwalkable Census Tract(s).
# For the walkable Census Tract(s)
tract_walkable_bb <- st_bbox(tract_walkable)
# For the unwalkable Census Tract(s)
tract_unwalkable_bb <- st_bbox(tract_unwalkable)
tract_walkable_bb_poly <- st_as_sfc(tract_walkable_bb)
tract_unwalkable_bb_poly <- st_as_sfc(tract_unwalkable_bb)
tmap_mode("view")
## ℹ tmap mode set to "view".
tm_shape(tract_walkable) + tm_polygons(col = "green", alpha = 0.6) +
tm_shape(tract_unwalkable) + tm_polygons(col = "red", alpha = 0.6) +
tm_shape(tract_walkable_bb_poly) + tm_borders(col = "seagreen", lwd = 3) +
tm_shape(tract_unwalkable_bb_poly) + tm_borders(col = "maroon", lwd = 3)
##
## ── tmap v3 code detected ───────────────────────────────────────────────────────
## [v3->v4] `tm_polygons()`: use `fill_alpha` instead of `alpha`.[v3->v4] `tm_polygons()`: use `fill_alpha` instead of `alpha`.
# //TASK //////////////////////////////////////////////////////////////////////
# =========== NO MODIFICATION ZONE STARTS HERE ===============================
# Get OSM data for the two bounding boxes
osm_walkable <- opq(bbox = tract_walkable_bb) %>%
add_osm_feature(key = 'highway',
value = c("primary", "secondary", "tertiary", "residential")) %>%
osmdata_sf() %>%
osm_poly2line()
osm_unwalkable <- opq(bbox = tract_unwalkable_bb) %>%
add_osm_feature(key = 'highway',
value = c("primary", "secondary", "tertiary", "residential")) %>%
osmdata_sf() %>%
osm_poly2line()
# =========== NO MODIFY ZONE ENDS HERE ========================================
# TASK ////////////////////////////////////////////////////////////////////////
# 1. Convert `osm_walkable` and `osm_unwalkable` into sfnetwork objects (as undirected networks),
# 2. Clean the network by (1) deleting parallel lines and loops, (2) creating missing nodes, and (3) removing pseudo nodes (make sure the `summarise_attributes` argument is set to 'first' when doing so).
net_walkable <- osm_walkable$osm_lines %>%
# Drop redundant columns
select(osm_id, highway) %>%
as_sfnetwork(directed = FALSE) %>%
activate("edges") %>%
filter(!edge_is_multiple()) %>%
filter(!edge_is_loop()) %>%
convert(to_spatial_smooth) %>%
convert(to_spatial_simple, summarise_attributes = "first")
net_unwalkable <- osm_unwalkable$osm_lines %>%
# Drop redundant columns
select(osm_id, highway) %>%
as_sfnetwork(directed = FALSE) %>%
activate("edges") %>%
filter(!edge_is_multiple()) %>%
filter(!edge_is_loop()) %>%
convert(to_spatial_smooth) %>%
convert(to_spatial_simple, summarise_attributes = "first")
# //TASK //////////////////////////////////////////////////////////////////////
# TASK //////////////////////////////////////////////////////////////////////
# Using `net_walkable` and`net_unwalkable`,
# 1. Activate the edge component of each network.
# 2. Create a `length` column.
# 3. Filter out short (<300 feet) segments.
# 4. Randomly Sample 100 rows per road type.
# 5. Assign the results to `edges_walkable` and `edges_unwalkable`, respectively.
# OSM for the walkable part
edges_walkable <- net_walkable %>%
activate("edges") %>%
mutate(length = st_length(geometry)) %>%
filter(as.numeric(length) > 300) %>%
st_as_sf() %>% # <—— critical
group_by(highway) %>%
slice_sample(n = 100, replace = FALSE) %>%
ungroup()
# OSM for the unwalkable part
edges_unwalkable <- net_unwalkable %>%
activate("edges") %>%
mutate(length = st_length(geometry)) %>%
filter(as.numeric(length) > 300) %>%
st_as_sf() %>% # <—— critical
group_by(highway) %>%
slice_sample(n = 100, replace = FALSE) %>%
ungroup()
# //TASK //////////////////////////////////////////////////////////////////////
# =========== NO MODIFICATION ZONE STARTS HERE ===============================
# Merge the two
edges <- bind_rows(edges_walkable %>% mutate(is_walkable = TRUE),
edges_unwalkable %>% mutate(is_walkable = FALSE)) %>%
mutate(edge_id = seq(1,nrow(.)))
# =========== NO MODIFY ZONE ENDS HERE ========================================
getAzimuth() function.In this assignment, you will collect two GSV images per road segment, as illustrated in the figure below. To do this, you will define a function that extracts the coordinates of the midpoint and the azimuths in both directions.
If you can’t see this image, try changing the markdown editing mode from ‘Source’ to ‘Visual’ (you can find the buttons in the top-left corner of this source pane).
getAzimuth <- function(line){
mid_p3 <- line %>%
st_line_sample(sample = c(0.48, 0.50, 0.52)) %>%
st_cast("POINT") %>%
st_coordinates()
# 4. Midpoint coordinates
mid_p <- mid_p3[2, ] # the 0.50 sample is index 2
# 5. Compute azimuths in both directions
# Direction 1: midpoint → point at 0.52
mid_azi_1 <- geosphere::bearing(mid_p3[2, ], mid_p3[3, ])
# Direction 2: midpoint → point at 0.48
mid_azi_2 <- geosphere::bearing(mid_p3[2, ], mid_p3[1, ])
# //TASK //////////////////////////////////////////////////////////////////////
# =========== NO MODIFICATION ZONE STARTS HERE ===============================
return(tribble(
~type, ~X, ~Y, ~azi,
"mid1", mid_p["X"], mid_p["Y"], mid_azi_1,
"mid2", mid_p["X"], mid_p["Y"], mid_azi_2
))
# =========== NO MODIFY ZONE ENDS HERE ========================================
}
Apply the getAzimuth() function to the
edges object. Once this step is complete, your data will be
ready for downloading GSV images.
# TASK ////////////////////////////////////////////////////////////////////////
# Apply getAzimuth() function to all edges.
# Remember that you need to pass edges object to st_geometry() before you apply getAzimuth()
edges_azi <- edges %>%
st_geometry() %>%
purrr::map_dfr(getAzimuth)
# //TASK //////////////////////////////////////////////////////////////////////
# =========== NO MODIFICATION ZONE STARTS HERE ===============================
edges_azi <- edges_azi %>%
bind_cols(edges %>%
st_drop_geometry() %>%
slice(rep(1:nrow(edges),each=2))) %>%
st_as_sf(coords = c("X", "Y"), crs = 4326, remove=FALSE) %>%
mutate(img_id = seq(1, nrow(.)))
# =========== NO MODIFY ZONE ENDS HERE ========================================
getImage <- function(iterrow){
# This function takes one row of `edges_azi` and downloads GSV image using the information from the row.
# TASK ////////////////////////////////////////////////////////////////////////
# 1. Extract required information from the row of `edges_azi`
# 2. Format the full URL and store it in `request`. Refer to this page: https://developers.google.com/maps/documentation/streetview/request-streetview
# 3. Format the full path (including the file name) of the image being downloaded and store it in `fpath`
type <- iterrow$type
location <- paste0(iterrow$Y, ",", iterrow$X) # lat,lng format
heading <- iterrow$azi %% 360
edge_id <- iterrow$edge_id
img_id <- iterrow$img_id
highway <- iterrow$highway
key <- Sys.getenv('google_API')
# Street View endpoint
endpoint <- "https://maps.googleapis.com/maps/api/streetview"
request <- paste0(endpoint,
"?size=640x640",
"&location=", location,
"&heading=", heading,
"&pitch=0",
"&key=", key)
fname <- glue::glue("GSV-nid_{img_id}-eid_{edge_id}-type_{type}-Location_{location}-heading_{heading}.jpg") # Don't change this code for fname
fpath <- file.path("GSV_images", fname)
# //TASK //////////////////////////////////////////////////////////////////////
# =========== NO MODIFICATION ZONE STARTS HERE ===============================
# Download images
if (!file.exists(fpath)){
download.file(request, fpath, mode = 'wb')
}
# =========== NO MODIFY ZONE ENDS HERE ========================================
}
Before you download GSV images, make sure the row
number in edges_azi is not too large! Each row corresponds
to one GSV image, so if the row count exceeds your API quota, consider
selecting different Census Tracts.
You do not want to run the following code chunk more than once, so the code chunk option
eval=FALSEis set to prevent the API call from executing again when knitting the script.
# =========== NO MODIFICATION ZONE STARTS HERE ===============================
for(i in 1:nrow(edges_azi)){
try({
getImage(edges_azi[i, ])
}, silent = TRUE)
Sys.sleep(0.1) # 100ms pause to avoid rate limits
}
# =========== NO MODIFY ZONE ENDS HERE ========================================
ZIP THE DOWNLOADED IMAGES AND NAME IT ‘gsv_images.zip’ FOR STEP 6.
Use this Google Colab script to apply the pretrained semantic segmentation model to your GSV images.
Once all of the images are processed and saved in your Colab session
as a CSV file, download the CSV file and merge it back to
edges_azi.
# TASK ////////////////////////////////////////////////////////////////////////
# Read the downloaded CSV file containing the semantic segmentation results.
seg_output <- read.csv("seg_output.csv")
# //TASK ////////////////////////////////////////////////////////////////////////
# TASK ////////////////////////////////////////////////////////////////////////
# 1. Join the `seg_output` data to `edges_azi`.
# 2. Calculate the proportion of predicted pixels for the following categories: `building`, `sky`, `road`, and `sidewalk`. If there are other categories you are interested in, feel free to include their proportions as well.
# 3. Calculate the proportion of greenness using the `vegetation` and `terrain` categories.
# 4. Calculate the building-to-street ratio. For the street, use `road` and `sidewalk` pixels; including `car` pixels is optional.
edges_seg_output <- edges_azi %>%
inner_join(seg_output, by= "img_id")
#percentages of building, sky, road, and sidewalk, greenness
edges_seg_output %<>%
mutate(pct_building = building/(768*768),
pct_sky = sky/(768*768),
pct_road = road/(768*768),
pct_sidewalk = sidewalk/(768*768),
prop_greenness = (vegetation + terrain) / (768*768),
building_street_ratio = building / (road + sidewalk))
# //TASK ////////////////////////////////////////////////////////////////////////
At the beginning of this assignment, you specified walkable and unwalkable Census Tracts. The key focus of this section is the comparison between these two types of tracts.
Create interactive maps showing the proportion of sidewalk, greenness, and the building-to-street ratio for both walkable and unwalkable areas. In total, you will produce 6 maps. Provide a brief description of your findings.
# TASK ////////////////////////////////////////////////////////////////////////
# Plot interactive map(s)
# As long as you can deliver the message clearly, you can use any format/package you want.
# Split into walkable and unwalkable
walkable_areas <- edges_seg_output %>% filter(is_walkable == TRUE)
unwalkable_areas <- edges_seg_output %>% filter(is_walkable == FALSE)
# tmap interactive mode
tmap_mode("view")
## ℹ tmap mode set to "view".
# Map
#Greeness proportion — walkable
tm_basemap("OpenStreetMap") +
tm_shape(edges_seg_output %>% filter(is_walkable == TRUE)) +
tm_dots(size = 0.7,
fill = "prop_greenness",
fill.scale = tm_scale(values = c("gray", "orange", "green", "blue")))
## Multiple palettes called "gray" found: "matplotlib.gray", "tableau.gray". The first one, "matplotlib.gray", is returned.
#Greeness proportion — unwalkable
tm_basemap("OpenStreetMap") +
tm_shape(edges_seg_output %>% filter(is_walkable == FALSE)) +
tm_dots(
size = 0.7,
fill = "prop_greenness",
fill.scale = tm_scale(values = c("darkgray", "yellow", "green", "darkgreen"))
)
#Sidewalk proportion — walkable
tm_basemap("OpenStreetMap") +
tm_shape(edges_seg_output %>% filter(is_walkable == TRUE)) +
tm_dots(size = 0.7,
col = "pct_sidewalk",
palette = c("#ffffd4", "#fed98e", "#fe9929", "#cc4c02"),
title = "Sidewalk %")
##
## ── tmap v3 code detected ───────────────────────────────────────────────────────
## [v3->v4] `tm_tm_dots()`: migrate the argument(s) related to the scale of the
## visual variable `fill` namely 'palette' (rename to 'values') to fill.scale =
## tm_scale(<HERE>).[tm_dots()] Argument `title` unknown.
#Sidewalk proportion — unwalkable
tm_basemap("OpenStreetMap") +
tm_shape(edges_seg_output %>% filter(is_walkable == FALSE)) +
tm_dots(size = 0.7,
col = "pct_sidewalk",
palette = c("#ffffd4", "#fed98e", "#fe9929", "#cc4c02"),
title = "Sidewalk %")
##
## ── tmap v3 code detected ───────────────────────────────────────────────────────
## [v3->v4] `tm_tm_dots()`: migrate the argument(s) related to the scale of the
## visual variable `fill` namely 'palette' (rename to 'values') to fill.scale =
## tm_scale(<HERE>).[tm_dots()] Argument `title` unknown.
tm_basemap("OpenStreetMap") +
tm_shape(edges_seg_output %>% filter(is_walkable == TRUE)) +
tm_dots(
size = 0.7,
col = "building_street_ratio",
style = "fixed",
breaks = c(0, 0.25, 0.5, 0.75, 1),
palette = c("#EED8AE", "#C4A484", "#8B5A2B", "brown"),
title = "Building-Street Ratio"
)
##
## ── tmap v3 code detected ───────────────────────────────────────────────────────
## [v3->v4] `tm_dots()`: instead of `style = "fixed"`, use fill.scale =
## `tm_scale_intervals()`.
## ℹ Migrate the argument(s) 'style', 'breaks', 'palette' (rename to 'values') to
## 'tm_scale_intervals(<HERE>)'[tm_dots()] Argument `title` unknown.
## Warning: Values have found that are higher than the highest break. They are
## assigned to the highest interval
# //TASK //////////////////////////////////////////////////////////////////////
Create boxplots for the proportion of each category (building, sky, road, sidewalk, greenness, and any additional categories of interest) and the building-to-street ratio for walkable and unwalkable tracts. Each plot should compare walkable and unwalkable tracts. In total, you will produce 6 or more boxplots. Provide a brief description of your findings.
# TASK ////////////////////////////////////////////////////////////////////////
# Create boxplot(s) using ggplot2 package.
# Create boxplots with walkability on x-axis
edges_seg_output %>%
pivot_longer(
cols = c(building_street_ratio, prop_greenness, pct_building,
pct_sky, pct_road, pct_sidewalk),
names_to = 'variable',
values_to = 'value'
) %>%
ggplot(aes(x = is_walkable, y = value, fill = is_walkable)) +
geom_boxplot(alpha = 0.7, outlier.size = 0.7, color = "gray30") +
scale_fill_manual(values = c("TRUE" = "blue", "FALSE" = "seagreen"),
labels = c("Unwalkable", "Walkable")) +
facet_wrap(~variable, scales = "free_y", nrow = 2) +
theme_bw(base_size = 13) +
labs(
title = "Distribution of Built Environment and Features by Walkability",
x = "Walkability",
y = "Proportion / Ratio",
fill = "Walkability"
) +
theme(
legend.position = "none",
strip.text = element_text(face = "bold"),
axis.text.x = element_text(angle = 0, hjust = 0.5)
)
# //TASK //////////////////////////////////////////////////////////////////////
Perform t-tests on the mean proportion of each category (building, sky, road, sidewalk, greenness, and any additional categories of interest) as well as the building-to-street ratio between street segments in the walkable and unwalkable tracts. This will result in 6 or more t-test results. Provide a brief description of your findings.
# TASK ////////////////////////////////////////////////////////////////////////
# Perform t-tests and report both the differences in means and their statistical significance.
# As long as you can deliver the message clearly, you can use any format/package you want.
walkable_building <- edges_seg_output %>% filter(is_walkable == TRUE) %>% pull(pct_building)
unwalkable_building <- edges_seg_output %>% filter(is_walkable == FALSE) %>% pull(pct_building)
walkable_sky <- edges_seg_output %>% filter(is_walkable == TRUE) %>% pull(pct_sky)
unwalkable_sky <- edges_seg_output %>% filter(is_walkable == FALSE) %>% pull(pct_sky)
walkable_road <- edges_seg_output %>% filter(is_walkable == TRUE) %>% pull(pct_road)
unwalkable_road <- edges_seg_output %>% filter(is_walkable == FALSE) %>% pull(pct_road)
walkable_sidewalk <- edges_seg_output %>% filter(is_walkable == TRUE) %>% pull(pct_sidewalk)
unwalkable_sidewalk <- edges_seg_output %>% filter(is_walkable == FALSE) %>% pull(pct_sidewalk)
walkable_greenness <- edges_seg_output %>% filter(is_walkable == TRUE) %>% pull(prop_greenness)
unwalkable_greenness <- edges_seg_output %>% filter(is_walkable == FALSE) %>% pull(prop_greenness)
walkable_b2s_ratio <- edges_seg_output %>% filter(is_walkable == TRUE) %>% pull(building_street_ratio)
unwalkable_b2s_ratio <- edges_seg_output %>% filter(is_walkable == FALSE) %>% pull(building_street_ratio)
t_test_building <- t.test(walkable_building, unwalkable_building)
t_test_sky <- t.test(walkable_sky, unwalkable_sky)
t_test_road <- t.test(walkable_road, unwalkable_road)
t_test_sidewalk <- t.test(walkable_sidewalk, unwalkable_sidewalk)
t_test_greenness <- t.test(walkable_greenness, unwalkable_greenness)
t_test_b2s_ratio <- t.test(walkable_b2s_ratio, unwalkable_b2s_ratio)
results_list <- list(
Building = list(w = walkable_building, u = unwalkable_building, t = t_test_building),
Sky = list(w = walkable_sky, u = unwalkable_sky, t = t_test_sky),
Road = list(w = walkable_road, u = unwalkable_road, t = t_test_road),
Sidewalk = list(w = walkable_sidewalk, u = unwalkable_sidewalk, t = t_test_sidewalk),
Greenness = list(w = walkable_greenness, u = unwalkable_greenness, t = t_test_greenness),
B2S_Ratio = list(w = walkable_b2s_ratio, u = unwalkable_b2s_ratio, t = t_test_b2s_ratio)
)
# Function to extract only t-statistic and p-value
extract_summary <- function(name, obj) {
data.frame(
category = name,
t_stat = as.numeric(obj$t$statistic),
p_value = obj$t$p.value
)
}
# Apply and combine
final_summary_table <- do.call(rbind,
mapply(extract_summary,
names(results_list),
results_list,
SIMPLIFY = FALSE))
final_summary_table
## category t_stat p_value
## Building Building 3.6237987 3.076272e-04
## Sky Sky -7.7045470 2.820830e-14
## Road Road 1.9560591 5.077806e-02
## Sidewalk Sidewalk -1.4631387 1.436852e-01
## Greenness Greenness 1.5430319 1.231305e-01
## B2S_Ratio B2S_Ratio 0.7513505 4.526245e-01
# //TASK //////////////////////////////////////////////////////////////////////