-
Notifications
You must be signed in to change notification settings - Fork 18
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
Attempt to resolve warnings in effect_N_discrete #97
Changes from 3 commits
35e6c52
669664b
bb0a7b9
d48af2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,9 +240,8 @@ deltaS_N = function(comm, ref_dens, inds){ | |
# rescale and interpolate this plot based S to individual based | ||
# using the ref_density (i.e., not the observed density) | ||
rescaled_effort = round(1:nplots * ref_dens) | ||
if (max(rescaled_effort) < max(inds)) | ||
warning('Extrapolating the rarefaction curve because the number of rescaled individuals is smaller than the inds argument') | ||
interp_S_samp = pchip(c(1, rescaled_effort), c(1, S_samp), inds) | ||
# No extrapolation of the rescaled rarefaction curve, only interpolation | ||
interp_S_samp = pchip(c(1, rescaled_effort), c(1, S_samp), inds[inds <= max(rescaled_effort)])[1:length(inds)] | ||
S_indiv = rarefaction(comm, 'indiv', inds) | ||
deltaS = interp_S_samp - S_indiv | ||
out = data.frame(inds = inds, deltaS = deltaS) | ||
|
@@ -572,8 +571,8 @@ effect_N_continuous = function(mob_in, S, group_levels, env_levels, group_data, | |
level_perm = group_levels[j] | ||
comm_level_perm = comm_perm[which(as.character(group_data) == level_perm), ] | ||
group_effect_N_perm = deltaS_N(comm_level_perm, plot_dens, | ||
ind_sample_size) | ||
effect_N_perm[, j] = group_effect_N_perm$deltaS | ||
ind_sample_size[ind_sample_size <= sum(comm_level_perm)]) | ||
effect_N_perm[, j] = group_effect_N_perm$deltaS[1:nrow(effect_N_perm)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have the same basic feeling here as in the previous comment. |
||
} | ||
effect_N_perm = effect_N_perm[complete.cases(effect_N_perm), ] | ||
# If the output is not long enough, fill it with NA's | ||
|
@@ -614,10 +613,12 @@ effect_N_discrete = function(mob_in, group_levels, ref_group, groups, | |
for (i in 1:nperm){ | ||
# swap plot abu between group 1 and each other group | ||
comm_perm = permute_comm(comm_levels, 'swapN', plot_levels) | ||
min_N = min(sum(comm_perm[plot_levels == as.character(ref_group), ]), | ||
sum(comm_perm[plot_levels == level, ])) | ||
N_eff_perm = sapply(c(as.character(ref_group), level), function(x) | ||
deltaS_N(comm_perm[plot_levels == x, ], plot_dens_level, | ||
ind_sample_size)$deltaS) | ||
null_N_deltaS_mat[i, ] = N_eff_perm[ , 2] - N_eff_perm[ , 1] | ||
ind_sample_size[ind_sample_size <= min_N])$deltaS) | ||
null_N_deltaS_mat[i, ] = (N_eff_perm[ , 2] - N_eff_perm[ , 1])[1:ncol(null_N_deltaS_mat)] | ||
setTxtProgressBar(pb, k) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here, but great job diving in and tracking these problems down. I'll test your code out on the case-studies to see if anything changes drastically on the results. |
||
k = k + 1 | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job fixing this! I can see why this code works but it will difficult to understand for future us and other users. If we don't know that R adds NA's to cells that are longer than the vector is defined across we would be scratching our heads right now. I would prefer one step where you define
interp_S_samp
and then a second step where you add NA's to that vector so that it has the same length asinds
. What do you think?