Code Monkey home page Code Monkey logo

ktc11's Introduction

Last-changedate minimal R version Licence Travis-CI Build Status Circle CI ORCiD

Research compendium for a report on archaeological excavations at Khao Toh Chong, Krabi, Thailand

Compendium DOI:

https://doi.org/10.6084/m9.figshare.2065602

The files at the URL above will generate the results as found in the publication. The files hosted at https://github.com/benmarwick/ktc11 are the development versions and may have changed since the report was published

Author of this repository:

Ben Marwick ([email protected])

Published in:

Marwick, B., Van Vlack, H.G., Conrad, C., Shoocongdej, R., Thongcharoenchaikit, C., Kwak, S. 2016 Adaptations to sea level change and transitions to agriculture at Khao Toh Chong rockshelter, Peninsular Thailand, Journal of Archaeological Science https://doi.org/10.1016/j.jas.2016.10.010

Overview of contents

This repository is our research compendium for our analysis of archaeological excavations at Khao Toh Chong, Krabi, Thailand. The compendium contains all data, code, and text associated with the publication (which is currently under review). The ktc_11_paper.Rmd file in the analysis/paper/ directory contains details of how all the analyses reported in the paper were conducted, as well as instructions on how to rerun the analysis to reproduce the results. The data/ directory in the analysis/ directory contains all the raw data. You can download the contents as a zip file from https://github.com/benmarwick/ktc11/archive/refs/heads/master.zip

The supplementary files

The analysis/ directory contains all the data files (in CSV format, in the data/ directory), the manuscript as submitted (in MS Word format, in the paper/ directory), a source file for the submitted paper (in R markdown format in the paper/ directory), an executed version of the supplementary file (in HTML format, in the paper/ directory) and all the figures that are included in the paper (in the figures/ directory).

The R package

This repository is organized as an R package. These functions are provided as a package because this makes it simpler to reuse the functions many times in the paper. It also makes it easier for others to use and adapt these functions on their own data. Nevertheless, this package has been written explicitly for this project and may not yet be suitable for more general purpose use.

To download the package source as you see it on GitHub, for offline browsing, use this line at the shell prompt:

git clone https://github.com/benmarwick/ktc11.git

Once the download is complete, open the ktc11.Rproj in RStudio to begin working with the package and compendium files.

If you want to re-run all the analyses in R, you can start by installing the compendium package with this line at the R prompt:

install.packages("devtools") # which in turn requires Rtools (if Windows) or Xcode (if OSX)

# outside of R, install Java using the lastest JDK from
# https://www.oracle.com/java/technologies/downloads/, then:
install.packages("rJava")

# this pkg has been removed from CRAN since the paper was published,
# so it wont install with the rest of the dependencies, and
# we need to get it from the archive:
devtools::install_version("maptools", "1.1-8")

# finally, install the package for this compendium:
devtools::install_github("benmarwick/ktc11")

Then set the working directory to the paper/ directory in this repository, and run rmarkdown::render("analysis/paper/ktc_11_paper.Rmd") file to generate the rendered copy (HTML or Word) and re-compute all the analyses.

The package has a number of dependencies on other R packages, and programs outside of R. Installing these can be time-consuming and complicated, so we've done two things to simplify access to the compendium. First is the packrat directory, which contains the source code for all the packages we depend on. If all works well, these will be installed on your computer when you open researchcompendium.Rproj in RStudio. Second is our Docker image that includes all the necessary software, code and data to run our analysis. The Docker image may give a quicker entry point to the project, and is more self-contained, so might save some fiddling with installing things.

The Docker image

A Docker image is a lightweight GNU/Linux virtual computer that can be run as a piece of software on Windows and OSX (and other Linux systems). To capture the complete computational environment used for this project we have a Dockerfile that specifies how to make the Docker image that we developed this project in. The Docker image includes all of the software dependencies needed to run the code in this project, as well as the R package and other compendium files. To launch the Docker image for this project, first, install Docker on your computer. At the Docker prompt, enter:

docker run -dp 8787:8787 benmarwick/ktc11

This will start a server instance of RStudio. Then open your web browser at localhost:8787 or or run docker-machine ip default in the shell to find the correct IP address, and log in with rstudio/rstudio.

Once logged in, use the Files pane (bottom right) to navigate to / (the root directory), then open the folder for this project, and open the .Rproj file for this project. Once that's open, you'll see the analysis/paper directory in the Files pane where you can find the R markdown document, and knit them to produce the results in the paper. More information about using RStudio in Docker is available at the Rocker wiki pages.

We developed and tested the package on this Docker container, so this is the only platform that We're confident it works on, and so recommend to anyone wanting to use this package to generate the vignette, etc.

Licenses:

Manuscript: CC-BY-4.0 http://creativecommons.org/licenses/by/4.0/

Code: MIT http://opensource.org/licenses/MIT year: 2016, copyright holder: Ben Marwick

Data: CC0 http://creativecommons.org/publicdomain/zero/1.0/ attribution requested in reuse

Dependencies:

I used RStudio on Ubuntu 16.04 and Windows 7. See the colophon section of the docx file in analysis/paper for a full list of the packages that this project depends on.

Contact:

Ben Marwick, Department of Anthropology Denny Hall 117, Box 353100, University of Washington Seattle, WA 98195-3100 USA

  1. (+1) 206.552.9450 e. [email protected]
  2. (+1) 206.543.3285 w. http://faculty.washington.edu/bmarwick/

ktc11's People

Contributors

benmarwick avatar cylerc avatar hgvanvlack avatar katrinleinweber avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

ktc11's Issues

Running the code in 2023

If attempting to run the code in the ktc_11_paper.Rmd, the simplest method is to follow the instructions in the README.md to stark Docker, generate a Docker container from the Dockerfile in this repository. This is the recommended approach.

If you want to run the code on a local installation of R, some modifications to the custom functions in the ktc11 package are necessary, due to updates in the packages we depend on. Here are the replacement functions, run these before interacting with any code in the Rmd file:

mean_difference_offset <- function (dates) 
{
  dates <- dates %>% dplyr::arrange(depth_below_surface)
  shell <- dates %>% dplyr::filter(Material == "shell")
  charcoal <- dates %>% dplyr::filter(Material == "charcoal")
  calibrated_dates_shell = Bchronology(ages = shell$RCAge, 
                                       ageSds = shell$RCAge_1s_error, 
                                       positions = shell$depth_below_surface, 
                                       positionThicknesses = rep(0.1,length(shell$RCAge)), 
                                       ids = shell$depth_below_surface, 
                                       calCurves = rep("intcal13", length(shell$RCAge)))
  calibrated_dates_charcoal = Bchronology(ages = charcoal$RCAge, 
                                          ageSds = charcoal$RCAge_1s_error, 
                                          positions = charcoal$depth_below_surface, 
                                          positionThicknesses = rep(0.1,length(charcoal$RCAge)), 
                                          calCurves = rep("intcal13", length(charcoal$RCAge)))
  shell_first_last <- summary(calibrated_dates_shell)[c(1, 
                                                        nrow(summary(calibrated_dates_shell))), ]
  calibrated_dates_charcoal_df <- summary(calibrated_dates_charcoal)
  calibrated_dates_charcoal_df$Depth_rounded <- round(calibrated_dates_charcoal_df$Depth, 
                                                      2)
  shell_charcoal_offset <- inner_join(shell_first_last, calibrated_dates_charcoal_df, 
                                      by = c(Depth = "Depth_rounded"))
  mean_difference <- mean(shell_charcoal_offset$`50%.x` - shell_charcoal_offset$`50%.y`)
  charcoal_dates_interp <- summary(calibrated_dates_charcoal)
  charcoal_dates_interp$midpoint <- charcoal_dates_interp$`2.5%` + 
    ((charcoal_dates_interp$`97.5%` - charcoal_dates_interp$`2.5%`)/2)
  return(list(mean_difference = mean_difference, charcoal_dates_interp = charcoal_dates_interp))
}
icp_aes_data_summary <- function (ktc11_raw_ICP_data) 
{
  KTC_ICP <- ktc11_raw_ICP_data
  KTConly <- KTC_ICP[grepl("KTC", KTC_ICP$Sample.ID) & !grepl("BLANK|Blank", 
                                                              KTC_ICP$Sample.ID) & !grepl("replica", KTC_ICP$Sample.ID), 
  ]
  blanks <- KTC_ICP[grepl("BLANK|Blank", KTC_ICP$Sample.ID), 
  ]
  replicates <- KTC_ICP[grepl("replica", KTC_ICP$Sample.ID), 
  ]
  KTConly$LogConc <- log10(abs(KTConly$Conc..Samp.1 * 1000))
  KTCconcs <- as.data.frame(na.omit(cbind(KTConly$Sample.ID, 
                                          KTConly$Elem, KTConly$LogConc)))
  colnames(KTCconcs) <- c("Sample.ID", "Element", "log_ugL")
  KTCconcs$log_ugL <- abs(as.numeric(as.character(KTCconcs$log_ugL)))
  KTCconcs$log_ugL <- as.numeric(ifelse(KTCconcs$log_ugL == 
                                          "NA", "0", KTCconcs$log_ugL))
  KTCconcs$log_ugL <- as.numeric(ifelse(KTCconcs$log_ugL == 
                                          "Inf", "0", KTCconcs$log_ugL))
  KTCcast <- tidyr::spread(KTCconcs, Element, log_ugL)
  row.names(KTCcast) <- KTCcast$Sample.ID
  KTCcast <- KTCcast[, -1]
  KTCcast <- KTCcast[, !(colSums(abs(KTCcast)) == 0)]
  depths <- c(0.02, 0.09, 0.22, 0.3, 0.4, 0.53, 0.72, 0.92, 
              1.1)
  KTCcast.strat <- KTCcast
  subset_elements <- c("Ca", "Sr", "Mn", "Fe", "Zn", "Na", 
                       "K", "Mg", "Ti")
  KTCcast.strat.subset <- KTCcast.strat[, names(KTCcast.strat) %in% 
                                          subset_elements]
  row.names(KTCcast.strat.subset) <- c("B1", "A2", "A3", "A4", 
                                       "A5", "A6", "A7U", "A8", "A7L")
  return(KTCcast.strat.subset)
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.