Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interpolate_to_heights drops nodes in largest size bracket #352

Open
aornugent opened this issue Oct 24, 2022 · 0 comments
Open

interpolate_to_heights drops nodes in largest size bracket #352

aornugent opened this issue Oct 24, 2022 · 0 comments
Assignees

Comments

@aornugent
Copy link
Collaborator

I discovered some unexpected behaviour in interpolate_to_heights. When using a coarse grid, individuals in the the largest class are removed, where instead I expected to keep them.

It's not quite right to represent their density at the highest interpolation point, so I think we need to append the largest individual in each time step.

Here is a pared down reprex using pieces of the code from interpolate_to_heights

# helper from `interpolate_to_heights`
f <- function(x, y, xout) {
  y_pred <- stats::spline(x, y, xout=xout, method="natural")$y
  y_pred[!dplyr::between(xout, min(x), max(x))] <- NA
  y_pred
}

# interpolation grid - expect to include density between 3-4
pts <- 1:4

# but nodes in large size bracket are not represented by final solution
data <- data.frame(step = 1,
                   species = 1,
                   time = 10,
                   height = c(0.1, 1.2, 2.3, 3.3),
                   density = c(0.1, 0.1, 0.1, 0.2))

data %>%
  dplyr::group_by(species, time, step) %>%
  dplyr::summarise(
    dplyr::across(where(is.double), ~f(height, .x, xout=pts)),
    .groups = "keep") 

# A tibble: 4 × 5
# Groups:   species, time, step [1]
  species  time  step height density
    <dbl> <dbl> <dbl>  <dbl>   <dbl>
1       1    10     1      1  0.102 
2       1    10     1      2  0.0914
3       1    10     1      3  0.163 
4       1    10     1     NA NA     
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants