Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3673060
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:41:09+00:00 2026-05-19T02:41:09+00:00

I need to smooth some simulated data, but occasionally run into problems when the

  • 0

I need to smooth some simulated data, but occasionally run into problems when the simulated ordinates to be smoothed are mostly the same value. Here is a small reproducible example of the simplest case.

> x <- 0:50
> y <- rep(0,51)
> loess.smooth(x,y)
Error in simpleLoess(y, x, w, span, degree, FALSE, FALSE, normalize = FALSE,  : 
   NA/NaN/Inf in foreign function call (arg 1)

loess(y~x), lowess(x,y), and their analogue in MATLAB produce the expected results without error on this example. I am using loess.smooth here because I need the estimates evaluated at a set number of points. According to the documentation, I believe loess.smooth and loess are using the same estimation functions, but the former is an “auxiliary function” to handle the evaluation points. The error seems to come from a C function:

> traceback()
3: .C(R_loess_raw, as.double(pseudovalues), as.double(x), as.double(weights), 
   as.double(weights), as.integer(D), as.integer(N), as.double(span), 
   as.integer(degree), as.integer(nonparametric), as.integer(order.drop.sqr), 
   as.integer(sum.drop.sqr), as.double(span * cell), as.character(surf.stat), 
   temp = double(N), parameter = integer(7), a = integer(max.kd), 
   xi = double(max.kd), vert = double(2 * D), vval = double((D + 
       1) * max.kd), diagonal = double(N), trL = double(1), 
   delta1 = double(1), delta2 = double(1), as.integer(0L))
2: simpleLoess(y, x, w, span, degree, FALSE, FALSE, normalize = FALSE, 
   "none", "interpolate", control$cell, iterations, control$trace.hat)
1: loess.smooth(x, y)

loess also calls simpleLoess, but with what appears to be different arguments. Of course, if you vary enough of the y values to be nonzero, loess.smooth runs without error, but I need the program to run in even the most extreme case.

Hopefully, someone can help me with one and/or all of the following:

  1. Understand why only loess.smooth, and not the other functions, produces this error and find a solution for this problem.
  2. Find a work-around using loess but still evaluating the estimate at a specified number of points that can differ from the vector x. For example, I might want to use only x <- seq(0,50,10) in the smoothing, but evaluate the estimate at x <- 0:50. As far as I know, using predict with a new data frame will not properly handle this situation, but please let me know if I am missing something there.
  3. Handle the error in a way that doesn’t stop the program from moving onto the next simulated data set.

Thanks in advance for any help on this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:41:09+00:00Added an answer on May 19, 2026 at 2:41 am

    For part 1:
    This took a bit of tracking down, but if you do:

    loess.smooth(x, y, family = "guassian")

    the model will fit. This arises due to the different defaults of loess.smooth and loess; the former has family = c("symmetric", "gaussian") whilst the latter has it reversed. If you trawl through the code for loess and loess.smooth, you’ll see that when family = "gaussian" iterations is set to 1. Otherwise it takes the value loess.control()$iterations. If you do iterations in simpleLoess, the following function call returns a vector of NaN:

    pseudovalues <- .Fortran(R_lowesp, as.integer(N), as.double(y), 
                as.double(z$fitted.values), as.double(weights), as.double(robust), 
                integer(N), pseudovalues = double(N))$pseudovalues
    

    Which causes the next function call to throw the error you saw:

    zz <- .C(R_loess_raw, as.double(pseudovalues), as.double(x), 
                as.double(weights), as.double(weights), as.integer(D), 
                as.integer(N), as.double(span), as.integer(degree), 
                as.integer(nonparametric), as.integer(order.drop.sqr), 
                as.integer(sum.drop.sqr), as.double(span * cell), 
                as.character(surf.stat), temp = double(N), parameter = integer(7), 
                a = integer(max.kd), xi = double(max.kd), vert = double(2 * 
                    D), vval = double((D + 1) * max.kd), diagonal = double(N), 
                trL = double(1), delta1 = double(1), delta2 = double(1), 
                as.integer(0L))
    

    This all relates to robust fitting in Loess (the method). If you don’t want/need a robust fit, use family = "gaussian" in your loess.smooth call.

    Also, note that the defaults for loess.smooth differ from those of loess, e.g. for 'span' and 'degree'. So carefully check out what models you want to fit and adjust the relevant function’s defaults.

    For part 2:

    DF <- data.frame(x = 0:50, y = rep(0,51))
    mod <- loess(y ~ x, data = DF)
    pred <- predict(mod, newdata = data.frame(x = c(-1, 10, 15, 55)))
    mod2 <- loess(y ~ x, data = DF, control = loess.control(surface = "direct"))
    pred2 <- predict(mod2, newdata = data.frame(x = c(-1, 10, 15, 55)))
    

    Which gives:

    > pred
     1  2  3  4 
    NA  0  0 NA 
    > pred2
    1 2 3 4 
    0 0 0 0
    

    The default won’t extrapolate if that was what you meant. I don’t see what the problem with using predict here is at all, in fact.

    For part 3:
    Look at ?try and ?tryCatch which you can wrap round the loess fitting function (loess.smooth say), which will allow computations to continue if an error in loess.smooth is encountered.

    You will need to handle the output of try or tryCatch by including something like (if you are doing this in a loop:

    mod <- try(loess.smooth(x, y))
    if(inherits(mod, "try-error"))
        next
    ## if here, model work, do something with `mod`
    

    I would probably combine try or tryCatch with fitting via loess and using predict for such a problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a input tag which is non editable, but some times i need
need ask you about some help. I have web app running in Net 2.0.
I need to send hundreds of newsletters, but would like to check first if
I'm doing some specific signal analysis, and I am in need of a method
I'm looking to put a horizontal fisheye/dock nav on my site, but I need
I need to draw a smooth line in OpenGL and here is what I
Need a function that takes a character as a parameter and returns true if
Need a way to allow sorting except for last item with in a list.
Need to an expression that returns only things with an I followed by either
Need to locate the following pattern: The letter I followed by a space then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.