salbeke / rKIN

Estimate Niche space using Kernel Density Estimates
4 stars 0 forks source link

Error in genCircle #11

Closed AylenM closed 1 year ago

AylenM commented 1 year ago

Hi everyone!

I was trying the example code to understand it: library(rKIN)

read in example data. Data contain 2 species, a habitat class and C/N values

data("rodents") head(rodents)

estimate niche overlap between 2 species using kernel UD and 3 confidence intervals

test.elp<- estEllipse(data=rodents, x="Ave_C", y="Ave_N", group="Species", levels=c(50, 75, 95))

Extract the area of each polygon

elp.area<- getArea(test.elp) elp.area

determine polygon overlap for all polygons

elp.olp<- calcOverlap(test.elp) elp.olp

plot the kernel estimates

plotKIN(test.elp, title="Test Bivariate Ellipse", x="Ave_C", y="Ave_N")

But I have obtained the following error: Error in genCircle(n = 100, radius) : could not find function "genCircle"

I´m not sure what´s the problem. I have already installed SIBER package. Can somebody help me to fix it?

Thank you so much in advance!

lliW3rd commented 1 year ago

Hello there!

I'm sorry to hear that you've encountered an issue while using rKIN. After some testing, I was unable to replicate the problem you mentioned. To help me solve this problem I was wondering if you could provide me with some more information, specifically your R session info.

Thank you!

AylenM commented 1 year ago

Thank you so much for the answer!

I have problems with some packages. I was able to solve it by directly executing the function first:

genCircle = function(n = 100, r) { theta = seq(0, 2 pi, length = n) x = r cos(theta) y = r * sin(theta) return(cbind(x,y)) }

But now, unfortunately, I can't use rKIN with my data, because it has less than ten point by grouping "Habitat" (two places). ¿Is it possible to modify the script to apply to an n= >5 & <10 in each group (disbalanced)?

Thank you so much in advance!

lliW3rd commented 1 year ago

In order to resolve the issue you had with genCircle and hopefully prevent others from running into the same problem could you please use the sessionInfo() function and copy and paste whatever is output in your console?

As far as your other issue goes if you are having an issue with the estEllipse function it is because it requires at least three rows of data to estimate the ellipse. Therefore, it is not possible to use this function with less than three rows of data.

However, if you have between three and ten rows of data, you can set the smallSamp argument in the estEllipse function to TRUE. This will allow the function to estimate the ellipse parameters with the available data. So if you have between 5 and 10 rows this should work as long as smallSamp = TRUE.

I hope this information helps you to resolve the issue. Please feel free to reach out to us if you have any further questions or concerns.

AylenM commented 1 year ago

Thank you for the replay. This is my output:

sessionInfo() R version 4.2.2 (2022-10-31 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale: [1] LC_COLLATE=Spanish_Argentina.utf8 LC_CTYPE=Spanish_Argentina.utf8
[3] LC_MONETARY=Spanish_Argentina.utf8 LC_NUMERIC=C
[5] LC_TIME=Spanish_Argentina.utf8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] reshape2_1.4.4 rKIN_0.3.0 ks_1.14.0 maptools_1.1-6 sp_1.6-0

loaded via a namespace (and not attached): [1] Rcpp_1.0.10 mclust_6.0.0 mvtnorm_1.1-3 lattice_0.20-45
[5] tidyr_1.3.0 deldir_1.0-6 digest_0.6.31 utf8_1.2.3
[9] plyr_1.8.8 R6_2.5.1 evaluate_0.20 pracma_2.4.2
[13] ggplot2_3.4.1 tensor_1.5 pillar_1.9.0 rlang_1.1.0
[17] rstudioapi_0.14 rpart_4.1.19 Matrix_1.5-1 goftest_1.2-3
[21] rmarkdown_2.21 splines_4.2.2 spatstat.explore_3.1-0 stringr_1.5.0
[25] foreign_0.8-83 polyclip_1.10-4 munsell_0.5.0 spatstat.data_3.0-1
[29] compiler_4.2.2 xfun_0.38 pkgconfig_2.0.3 mgcv_1.8-41
[33] rgeos_0.6-2 htmltools_0.5.5 tidyselect_1.2.0 spatstat.random_3.1-4 [37] tibble_3.2.1 gridExtra_2.3 hdrcde_3.4 fansi_1.0.4
[41] withr_2.5.0 dplyr_1.1.1 MASS_7.3-58.1 grid_4.2.2
[45] nlme_3.1-160 gtable_0.3.3 lifecycle_1.0.3 magrittr_2.0.3
[49] scales_1.2.1 KernSmooth_2.23-20 cli_3.6.1 stringi_1.7.12
[53] farver_2.1.1 spatstat_3.0-3 spatstat.linnet_3.0-6 ggfortify_0.4.16
[57] generics_0.1.3 vctrs_0.6.1 spatstat.utils_3.0-2 RColorBrewer_1.1-3
[61] tools_4.2.2 glue_1.6.2 purrr_1.0.1 spatstat.model_3.2-1
[65] abind_1.4-5 fastmap_1.1.1 yaml_2.3.7 spatstat.sparse_3.0-1 [69] colorspace_2.1-0 spatstat.geom_3.1-0 knitr_1.42

Mi problem of data was solved with smallSamp=T. I was able to do all the analysis.

Thank you again!!