R/runall.R

Defines functions run.all

Documented in run.all

#' run.all
#'
#' @param sightingdata
#' @param alpha
#' @param test.year
#' @param data.out
#' @param plot
#'
#' @return
#' @export
#'
#' @examples
run.all <-
  function(sightingdata, alpha, test.year, data.out, plot){

    ## some warnings

    if(!is.logical(plot))
      stop('plot must be logical', call.=FALSE)

    ## The functions
    O    <-  OLE(sightingdata, alpha)
    sol1 <-  Solow1993.eq2(sightingdata, alpha, test.year, data.out)
    sol2 <-  Solow2005.eq7(sightingdata, alpha, test.year, data.out)
    revsol2 <- Reverse_solow2005(sightingdata, alpha, test.year, data.out)

    if(data.out==F){
      k=4
      results <- data.frame(Test=character(length=k),
                            Estimate=numeric(length=k))
      results$Test         <- c("OLE","Solow1993.eq2", "Solow2005.eq7", "Rev_Solow2005")
      results$Estimate[1]  <- O$Estimate
      results$Estimate[2]  <- sol1$Estimate
      results$Estimate[3]  <- sol2$Estimate
      results$Estimate[4]  <- revsol2$Estimate

      for(t in 1:length(results$Estimate)){

        results$Estimate[t] <-ifelse(results$Estimate[t]>test.year, NA, results$Estimate[t])}
    }
    else{
      sol1$code<-"Solow1993.eq2"
      sol2$code<-"Solow2005.eq7"
      revsol2$code<-"Rev_Solow2005"
      results<-rbind(sol1, sol2,revsol2)
    }
    if(plot==T){
      plotted <- ggplot2::ggplot(results, aes(x=yrs, y=chance, group=code, color=code)) +
        geom_line()

    }
    if(plot==T){
      list(plotted, results)
    }
    else{
      return(results)
    }

  }
Clara-Casabona/ExtinctModels documentation built on Dec. 17, 2021, 2:05 p.m.