# Nonlinear Least Squares r | R Nonlinear Least Square - r - learn r - r programming

- When displaying real world data for regression analysis, we observe that it is rarely the case that the equation of the model is a linear equation giving a linear graph.
- Most of the time, the calculation of the model of real world data involves mathematical functions of higher degree like an exponent of 3 or a sin function.
- In such a situation, the plot of the model gives a curve rather than a line.
- The goal of both linear and non-linear regression is to adjust the values of the model's constraints to find the line or curve that comes closest to your data.
- On finding these values we will be able to estimate the response variable with good accuracy.
- In Least Square regression, we establish a regression model in which the sum of the squares of the vertical distances of different points from the regression curve is minimized.
- We generally start with a defined model and assume some values for the coefficients.
- We then apply the nls() function of R to get the more accurate values along with the confidence intervals.

r programming non linear least square

## Syntax

- The basic syntax for creating a nonlinear least square test in R is

**formula**is a nonlinear model formula including variables and parameters.**data**is a data frame used to evaluate the variables in the formula.**start**is a named list or named numeric vector of starting estimates.

## Example

- We will consider a nonlinear model with assumption of initial values of its coefficients.
- Let's consider the below equation for this purpose

- Let's assume the initial coefficients to be 1 and 3 and fit these values into nls() function.

- When we execute the above code, it produces the following result

- We can conclude that the value of b1 is more close to 1 while the value of b2 is more close to 2 and not 3.