[R] About uniroot error

Tania Morgado Garcia tmg1970 @end|ng |rom gm@||@com
Tue Sep 25 17:46:58 CEST 2018


Thanks for your reply. You're right, return a vector. An example of the
dataset:
ts pu carbono
1 15 2.04
1 37 1.27
1 55 0.93
1 80 0.5
1 105 0.49
1 22 2.08
1 41 1.43
1 65 0.78

The data that originate the FCOS and FRCOS pattern functions are others,
which I only use to obtain the functions.

Thanks again

El mar., 25 sept. 2018 a las 10:29, Michael Dewey (<lists using dewey.myzen.co.uk>)
escribió:

> Dear Tania
>
> Without your dataset I am not sure but a comment below to suggest where
> to look next.
>
> On 24/09/2018 18:37, Tania Morgado Garcia wrote:
> > Thanks for your answers. I continue to learn R and now I am detained in
> an
> > error with uniroot that I see happens to others but I can not find the
> > solution. Next the code
> >
> > x1 <- BAaxOrd$V1
> > y1 <- BAaxOrd$V2
> > x1R <- BAaxOrdRCOS$V1
> > y1R <- BAaxOrdRCOS$V2
> > FCOS1 <- splinefun(smooth.spline(x1,y1))
> > FRCOS1 <- splinefun(smooth.spline(x1R,y1R))
> > FCOS1 <- Vectorize(FCOS1)
> > FRCOS1 <- Vectorize(FRCOS1)
> >
> > req(input$file1)
> >        tryCatch(
> >        {
> >          df <- read.csv(input$file1$datapath,
> >                         header = input$header,
> >                         sep = "\t",
> >                         quote = '"')
> >        },
> >        error = function(e) {
> >          # return a safeError if a parsing error occurs
> >          stop(safeError(e))
> >        }
> >      )
> >
> >      #if(input$disp == "head") {
> >       # return(head(df))
> >      #}
> >      #else {
> >
> >        # Determine Carbon Reserve
> >        for (row in 1:nrow(df)) {
> >          if(df$ts==1) {
> >             prof <-
> > uniroot(f=function(x){FCOS1(x1)-df$carbono},interval=c(0,20))$root
> >             limsup <- prof + df$pu
> >             reserva <- integrate(FRCOS1,prof,limsup)$value
> >          }
>
> Are you sure that FCOS(x1) - df$carbono returns a scalar? It looks as
> though it returns a vector to me but without your data I am not sure so
> ignore my post if it does.
> >
> > The if is because there are several types of soil, but I only put one.
> The
> > error is
> >
> > Warning in if (is.na(f.lower)) stop("f.lower = f(lower) is NA") :
> >    the condition has length > 1 and only the first element will be used
> > Warning in if (is.na(f.upper)) stop("f.upper = f(upper) is NA") :
> >    the condition has length > 1 and only the first element will be used
> > Warning: Error in uniroot: f() values at end points not of opposite sign
> >
> > The file that I load with data has a single row with the values ts = 1,
> > carbon = 2.04 and pu = 15 (I left only that row to be able to determine
> the
> > origin of the error). The functions FCOS1 and FRCOS1 are monotone
> > decreasing.Graphic attachment of FCOS1
> >
> > I would appreciate some help in this regard
> >
> > thanks a lot
> > ______________________________________________
> > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
> --
> Michael
> http://www.dewey.myzen.co.uk/home.html
>

	[[alternative HTML version deleted]]




More information about the R-help mailing list