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

  • SEARCH
  • Home
  • 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 6335107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:47:33+00:00 2026-05-24T18:47:33+00:00

Is there any way to allow my nls to have 0 residual error when

  • 0

Is there any way to allow my nls to have 0 residual error when it makes a non linear fit? I have cases in my data where the fit made should have 0 error, but nls always fails and spits out an error.

Can anyone show me:

  1. How do I test if this is the error being spit out by nls?
  2. How to allow for 0 error cases? (Perfect fits)

This is my nls call:

fit <- nls(y ~ ifelse(g, m1 * (x - x0) + y0, m2 * (x - x0) + y0),
            start = c(m1 = -1, m2 = 1, y0 = 0, x0 = split),
            algorithm = "port",
            lower = c(m1 = -Inf, m2 = -Inf, y0 = -Inf, x0 = split),
            upper = c(m1 = Inf, m2 = Inf, y0 = Inf, x0 = (split+1)),
            data=data.frame(x,y))
  • 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-24T18:47:34+00:00Added an answer on May 24, 2026 at 6:47 pm

    As mentioned in a previous answer, ?nls explicitly states that you should not use nls for 0 error data. To directly quote the help file for the function you are using:

    Do not use nls on artificial “zero-residual” data.

    The nls function uses a relative-offset convergence criterion that
    compares the numerical imprecision at the current parameter estimates
    to the residual sum-of-squares. This performs well on data of the form

    y = f(x, θ) + eps

    (with var(eps) > 0). It fails to indicate convergence on data of the
    form

    y = f(x, θ)

    because the criterion amounts to comparing two components of the
    round-off error. If you wish to test nls on artificial data please add
    a noise component, as shown in the example below.

    A potentially dangerous option would be to use warnOnly = TRUE to force nls to return prior to convergence with a warning only (no error):

    x <- -(1:100)/10
    y <- 100 + 10 * exp(x / 2)
    nlmod <- nls(y ~  Const + A * exp(B * x),control = nls.control(warnOnly = TRUE))
    

    The above example was also taken nearly directly from ?nls.

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

Sidebar

Related Questions

Is there any way to allow non-Administrator users to install, upgrade or uninstall an
Is there any clean way to allow a user to select multiple non continuos
Is there any way to allow search engines to list JSON or XML ajax
Is there any way to allow people that has a facebook account to post
Is there any way to allow the user to select the year on the
Anyone know what is going on at here? Is there any way to allow
Is there any official way to allow a CSV formatted file to allow comments,
Is there any way to allow me to trace button click in which webpage.
Is there any way to allow the user to create an event using the
When a modal dialog is opened, is there any way to allow user close

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.