Created
September 16, 2018 17:36
-
-
Save benmarwick/0969c5bad79af1e9dbe4a0212c9ee92a to your computer and use it in GitHub Desktop.
Code for workshop on R for archaeologists at the National Taiwan University as part of my BITSS series
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load the libraries | |
library(tidyverse) | |
library(readxl) | |
# load the data | |
pottery <- | |
read_excel("data/HTSKY-RIM.xlsx", | |
col_types = "text") | |
# inspect the data | |
View(pottery) | |
str(pottery) | |
names(pottery) | |
# clean the data | |
pottery_clean <- | |
pottery %>% | |
mutate_at(c("RimD", "LipT", "NeckH", "Weight", "Thickness"), | |
as.numeric) | |
# analyse a little | |
pottery_clean %>% | |
count(Area, sort = TRUE) | |
pottery_clean %>% | |
count(Sarea, sort = TRUE) | |
# plot some data | |
ggplot(pottery_clean, | |
aes(Weight)) + | |
geom_histogram() + | |
scale_x_log10() | |
ggplot(pottery_clean, | |
aes(NeckH, | |
LipT)) + | |
geom_point() + | |
theme_minimal() | |
ggplot(pottery_clean, | |
aes(Slayer, | |
LipT)) + | |
geom_boxplot() + | |
geom_jitter() + | |
theme_minimal() | |
# plot many variables together | |
pottery_clean %>% | |
select(Slayer, RimD:Weight) %>% | |
gather(variable, value, -Slayer) %>% | |
filter(!is.na(Slayer)) %>% | |
ggplot(aes(Slayer, | |
value)) + | |
geom_boxplot() + | |
geom_jitter(alpha = 0.3) + | |
facet_wrap( ~ variable, scales = "free_y") + | |
theme_minimal() | |
# save the plot | |
ggsave("pottery_metrics_by_layer.png") | |
# statistical tests | |
# ANOVA | |
aov_lipT_by_layer <- | |
aov(data = pottery_clean, | |
LipT ~ Slayer) | |
summary(aov_lipT_by_layer) | |
TukeyHSD(aov_lipT_by_layer) | |
# chi-square | |
# chi-sq | |
pottery_clean_table <- | |
pottery_clean %>% | |
count(Rim, Area) %>% | |
spread(Rim, n) %>% | |
select(-Area) %>% | |
filter_all(any_vars(. > 5)) %>% | |
select_if( ~!any(is.na(.))) %>% | |
select(-`<NA>`) | |
chisq.test(pottery_clean_table) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment