Skip to content

Commit

Permalink
add SMA-allometries.R
Browse files Browse the repository at this point in the history
  • Loading branch information
brymz committed Apr 10, 2018
1 parent 6ab7849 commit d958346
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
49 changes: 49 additions & 0 deletions GeneralAllometry/SMA-allomtries.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
### This script builds a table of allometry predictions (L~D, D~M)
### at branch levels for cherry and apples. The results are reported in the
### manuscript.

library('smatr')

test_slope <- function(name, formulas, data){
sma_row <- c(name)
for (i in 1:length(formulas)) {
test <- sma(formulas[i][[1]], log = 'xy', data = data)
sma_row <- c(sma_row, params_out(test))
}
return(sma_row)
}

params_out <- function(sma_data){
return (paste("a: ", round(sma_data$coef[[1]][2,1],2), " [ ",
round(sma_data$coef[[1]][2,2],2), " , ",
round(sma_data$coef[[1]][2,3],2), " ]; b: ",
round(sma_data$coef[[1]][1,1],2), " [ ",
round(sma_data$coef[[1]][1,2],2), " , ",
round(sma_data$coef[[1]][1,3],2), " ]; ",
round(sma_data$r2[[1]], 3), sep = ""))
}

branch_size <- read.csv("BranchSegments.csv", sep = ',', header = T)
group_data <- list()
group_data[[1]] <- branch_size[branch_size$species=="cherry",]
group_data[[2]] <- branch_size[branch_size$species=="apple",]

groups <- c("cherry", "apple")
relationships <- c("L~D (Segment)", "(Path)", "(Subtree)",
"M~D (Segment)", "(Path)", "(Subtree)")
branch_formulas <- c(length_cm ~ diameter_mm,
path_length ~ diameter_mm,
tot_length ~ diameter_mm,
stem_m ~ diameter_mm,
path_stem_m ~ diameter_mm,
tot_stem_m ~ diameter_mm)

output <- c()
for (i in 1:2){
output <- rbind(output, test_slope(groups[i], branch_formulas,
group_data[[i]]))
}

colnames(output) <- c('group', relationships)

write.csv(output, "allometries.csv")
3 changes: 3 additions & 0 deletions GeneralAllometry/allometries.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"","group","L~D (Segment)","(Path)","(Subtree)","M~D (Segment)","(Path)","(Subtree)"
"1","cherry","a: 0.83 [ 0.76 , 0.91 ]; b: 0.51 [ 0.4 , 0.62 ]; 0.006","a: 0.99 [ 0.93 , 1.05 ]; b: 0.64 [ 0.56 , 0.73 ]; 0.605","a: 1.53 [ 1.45 , 1.62 ]; b: 0.08 [ -0.05 , 0.2 ]; 0.613","a: 2.09 [ 2.01 , 2.17 ]; b: -0.75 [ -0.87 , -0.64 ]; 0.825","a: 2.33 [ 2.27 , 2.4 ]; b: -0.9 [ -0.99 , -0.81 ]; 0.92","a: 2.49 [ 2.43 , 2.55 ]; b: -1.05 [ -1.14 , -0.96 ]; 0.926"
"2","apple","a: -1.15 [ -1.27 , -1.04 ]; b: 3.63 [ 3.45 , 3.82 ]; 0.024","a: 1.1 [ 1.02 , 1.19 ]; b: 0.32 [ 0.19 , 0.46 ]; 0.442","a: 1.65 [ 1.54 , 1.76 ]; b: -0.43 [ -0.61 , -0.26 ]; 0.577","a: 2.11 [ 1.99 , 2.23 ]; b: -0.67 [ -0.87 , -0.48 ]; 0.688","a: 2.36 [ 2.28 , 2.45 ]; b: -0.93 [ -1.07 , -0.79 ]; 0.867","a: 2.57 [ 2.49 , 2.66 ]; b: -1.21 [ -1.35 , -1.07 ]; 0.892"

0 comments on commit d958346

Please sign in to comment.