Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 628e0bb
  • /
  • calanda_bulk_density.R
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:3e27dcfda1f9d094fd202b5a7e1ea096eeafab34
directory badge
swh:1:dir:628e0bb78ed29b0ddd35f8be6bd97119400d5190

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
calanda_bulk_density.R
################################################################################
#### Project: Lowland plant migrations alpine soil C loss
#### Title:   Check that bulk density doesn't change
#### Author:  Tom Walker (thomas.walker@usys.ethz.ch)
#### Date:    25 January 2022
#### ---------------------------------------------------------------------------

#### PROLOGUE ------------------------------------------------------------------

## Options ----
# remove objects from global environment
rm(list = ls())
# R session options (no factors, bias against scientific #s)
options(
  stringsAsFactors = F,
  scipen = 6
)

## Libraries ----
# standard library set
library(nlme)
library(emmeans)
library(multcomp)
library(tidyverse)
source("./r_code/mm2in.R")


#### DATA ----------------------------------------------------------------------

## Load ----
bd <- data.table::fread("./data/field_calanda_bd.csv", data.table = F)

## Format ----
bd <- bd %>%
  mutate(treatment = ifelse(treatment == "I", "WL", treatment)) %>%
  mutate(treatment = factor(treatment))


#### ANALYSE -------------------------------------------------------------------

## Model ----
m1 <- lme(
  BD ~ treatment, 
  random = ~ 1 | block,
  data = bd,
  method = "ML"
)

## Validate ----
r1 <- residuals(m1, type = "normalized")
par(mfrow = c(1, 3))
plot(r1 ~ fitted(m1))
boxplot(r1 ~ bd$treatment)
hist(r1)

#### Significance ----
anova(m1, update(m1, ~.- treatment))
m1reml <- update(m1, method = "REML")
emmeans(m1reml, pairwise ~ treatment)
summary(glht(m1reml, mcp(treatment = "Tukey")))


#### PLOT ----------------------------------------------------------------------

## Create dataset ----
sumBD <- bd %>%
  group_by(treatment) %>%
  summarise(
    mean = mean(BD, na.rm = T),
    se = sd(BD, na.rm = T)/sqrt(n())
  )

#### Plot ----
bdPlot <- ggplot(sumBD) +
  theme_bw() +
  theme(panel.grid = element_blank()) +
  coord_cartesian(ylim = c(0.5, 0.675)) +
  aes(x = treatment, 
      y = mean, 
      ymax = mean + se, 
      ymin = mean - se) +
  geom_errorbar(width = 0.2) +
  geom_bar(stat = "identity", col = "black", fill = "white") +
  xlab("") +
  ylab(expression(paste("Bulk density (g ", cm^{-3}, ")", sep = "")))
bdPlot

#### Write file ----

postscript(
  file = "./figure_builds/bulk_density.eps",
  width = mm2in(40),
  height = mm2in(60)
)
bdPlot
dev.off()

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API