Giter VIP home page Giter VIP logo

ethnobotanyr's People

Contributors

cwwhitney avatar davisvaughan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ethnobotanyr's Issues

The vignette is wrong about FL

FLs is calculated correctly, as in the cited paper. But it is stated wrongly in the vignette.
Where it states URs it should state FCs instead, as this is what you actually do.

It should also state that the values are multiplied by 100, both in the vignette and in the help file.

CIs, UVs, and simple_UVs are the same thing

The calculation of both CIs UVs and simple UVs seems over excessive.
They all calculate the exact same thing correctly - but it seems error prone to do it in three different ways.

All three implementations calculate the exact same thing, and I would suggest using only one function and letting the other functions just refer to that one function.

The implementation of CIs looks cleanest and I would suggest the others just pointed to that.

RFCs doesn't work if informant is numeric

Due to the use of this function:

RFCdata <- RFCdata %>% dplyr::mutate_if(is.numeric, ~1 * 
                                          (. != 0))

The function doesn't work if the informant column is numeric. I am afraid that this error might occur elsewhere as well, but I have not come across it so far.

The line can simply be replaced with, which would work:

RFCdata$FCps <- (RFCdata$FCps > 0) * 1

CVe is calculated wrongly

CVe gives the wrong result + it gives a warning because of the bind_cols command.

  1. It binds columns together with rows in different orders.
  2. The final calculation is where you multiply by a sum, I think is wrong - but a choice.
    a. You calculate it as stated verbatim in Reyes-Garcia et al. 2006, but I think they made an error when they wrote it. I doesn't make sense or add any information to multiply all the values by the same number.
    b. The way Tardio and Pardo-de-Santayana 2008 quote it is more sensical. Where they don't take the sum. My correction is based on a shift from Reyes-Garcia et al. 2006 verbatim to the interpretation of CV_e (or CV_s as they call it) in Tardio and Pardo-de-Santayana 2008.
    c. The latter interpretation which I suggest would also follow the interpretation in B. Hoffman, T. Gallaher, Importance indices in ethnobotany. Ethnobot. Res. Appl. 5, 201โ€“218 (2007).

I have highlighted the problematic sections below and my suggestions for fixing them.

CVe <- FCs <- UR_UN_FC <- CVe <- URdata <- data_Ci <- data_URs <- URps <- sp_name <- informant <- NULL
URdata <- ethnobotanydata
URS <- URs(URdata)
NUS <- NUs(URdata)
NUS$Uce <- NUS$NUs/ncol(dplyr::select(URdata, -informant, -sp_name))
FCS <- FCs(URdata)
FCS$Ice <- FCS$FCs/length(unique(URdata$informant))

# ERROR 1:
# REMOVE
# UR_UN_FC <- dplyr::bind_cols(NUS, URS, FCS)
# REPLACE WITH THIS:
UR_UN_FC <- dplyr::left_join(NUS, URS) %>% dplyr::left_join(FCS)

UR_UN_FC$IUce <- UR_UN_FC$URs/length(unique(URdata$informant))

# ERROR 2 (Maybe???)
# REMOVE
# UR_UN_FC$CVe <- UR_UN_FC$Uce * UR_UN_FC$Ice * sum(UR_UN_FC$IUce)
# REPLACE WITH THIS:
UR_UN_FC$CVe <- UR_UN_FC$Uce * UR_UN_FC$Ice * UR_UN_FC$IUce

CVe <- dplyr::select(UR_UN_FC, sp_name, CVe) %>% dplyr::arrange(-CVe) %>% 
  dplyr::mutate(CVe = round(CVe, 3))
as.data.frame(CVe)

Adding functions

Add more functions

  • informant consensus factor (Fic)
  • UV
  • FL
  • others?

Why do all the functions return data frames?

All functions seem to return a result using as.data.frame(...).

The built in example dataset is also a data frame class.

Since the package is marketed as an intended expansion package working with tidyverse is should probably be updated to tibbles.

RI index is calculated wrongly I think

The code doesn't seem to calculate the Relative Importance Index as in the paper you cite.

I think the RFCs(max) part of the code is wrong.

Your code says:
RFCs <- RFCdata %>% dplyr::group_by(sp_name) %>% dplyr::summarize(RFCs = sum(FCps/(length(unique(informant))))) %>% dplyr::arrange(-RFCs)

Which gives FCs over total number of informants not over the max(FCs). There are 20 unique informants for all species in the test dataset, even though not all of them mention all species.

For the test dataset your code gives this:

> ethnobotanyR::RIs(ethnobotanydata)
  sp_name   RIs
1    sp_c 0.925
2    sp_a 0.812
3    sp_d 0.800
4    sp_b 0.738

while the RI should be:

> RFCsmax <- FCs(ethnobotanydata) %>% mutate(RFCsmax = FCs/max(FCs))
> RNUsmax <- NUs(ethnobotanydata) %>% mutate(RNUsmax = NUs/max(NUs))
> 
> RI <- left_join(RFCsmax, RNUsmax, by = "sp_name")
> RI %>% mutate(RIs = (RFCsmax + RNUsmax) / 2) %>% arrange(desc(RIs))
  sp_name FCs   RFCsmax NUs RNUsmax       RIs
1    sp_c  17 1.0000000   8   1.000 1.0000000
2    sp_a  15 0.8823529   7   0.875 0.8786765
3    sp_d  12 0.7058824   8   1.000 0.8529412
4    sp_b  12 0.7058824   7   0.875 0.7904412

I have spent some time trying to understand this discrepancy. If I have misunderstood the paper or your function please let me know. I am teaching a course next month using your package and before i confuse my students too much, I would like to know if I'm mistaken or the package has a bug.

If I am right your code could read:

RFCs <- RFCdata %>% dplyr::group_by(sp_name) %>% dplyr::summarize(FCs = sum(FCps)) %>%
  mutate(RFCs = FCs/max(FCs), FCs = NULL) %>% 
  dplyr::arrange(-RFCs)

Time related

Look at possible ways to use area curves and time curves for quantitative analysis.

FLs doesn't work with tibbles

Since the package is marketed as an addition to tidyverse, I think it is important all functions work with tibbles.

The function FLs() doesn't work with tibbles due to the functions use of reshape::melt(...).

The easiest fix (but not the best) is simply to replace reshape with reshape2.

The function could be rewritten to be based on tidyverse functions, to avoid problems like this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.