-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculate_k.Rmd
54 lines (40 loc) · 1.22 KB
/
calculate_k.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
---
title: "calculate k"
author: "Melanie K. Taylor"
date: "2024-07-16"
output: pdf_document
---
```{r}
#if needed install tidyverse and litterfitter
library(litterfitter)
library(tidyverse)
library(dplyr)
#set working directory
setwd("C:/Users/melanietaylor/Desktop")
#load litter values
lit <- read.csv("C:/Users/melanietaylor/Desktop/k_values_g_per_g_with_duration_in_days_cornelissen.csv")
```
```{r}
#calculate proportion litter remaining
#calculate time in years
lit <- lit %>%
drop_na(proportion_mass_loss) %>%
mutate(p_litter_remaining = 1 - proportion_mass_loss,
length_yr = length_decomp_days/365)
#Get unique species
all_species <- unique(lit$speciesname)
output <- data.frame(species = character(),
k = double())
#started to try to write loop:
for (species in all_species) {
df <- filter(lit, speciesname == species)
fit <- fit_litter(time=c(0, df$length_yr),
mass.remaining = c(1, df$p_litter_remaining),
model = "neg.exp",
iters = 500)
line_output <- data.frame(species=species,
k=coef(fit))
output <- rbind(output, line_output)
}
write.csv(output, "k_values_cornelissen.csv")
```