diff options
Diffstat (limited to 'src/utils.jl')
-rw-r--r-- | src/utils.jl | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/utils.jl b/src/utils.jl index d4d719b..946e224 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -6,13 +6,13 @@ function ndetects(y::Array) mapslices(sum2, y, dims=2) end -#Simulate random covariate frame based on provided formula" +#Simulate random covariate frame based on provided formula function gen_covs(f::FormulaTerm, n::Int) covs = varnames(f).rhs if isnothing(covs) return DataFrame(_dummy=ones(n)) end nc = length(covs) out = DataFrame(reshape(rand(Normal(0,1), n*nc), n, nc)) - DataFrames.names!(out, covs) + DataFrames.rename!(out, covs) out end @@ -22,3 +22,27 @@ function rep_missing!(ynew::Array, y::Array) if length(na_idx) == 0 return nothing end ynew[na_idx] = fill(missing, length(na_idx)) end + +#Get appropriate value of K +function check_K(K::Int, y::Array{Union{Missing,Int},2}) + if(K < (maximum(skipmissing(y)))) + error("K should be larger than the maximum observed abundance") + end + K +end + +function check_K(K::Nothing, y::Array{Union{Missing,Int},2}) + maximum(skipmissing(y)) + 20 +end + +#Get minimum bound for integrating over possible abundance values K +#Minimum bound = maximum abundance ever observed at a site +function get_Kmin(y::Array{Union{Missing,Int64},2}) + N = size(y, 1) + kmin = zeros(Int64, N) + for n in 1:N + if(all(ismissing.(y[n, :]))) continue end + kmin[n] = maximum(skipmissing(y[n, :])) + end + kmin +end |