# Beyond Linear Modeling using R (part-1)

Many problems in econometrics are based on the assumption that two (or more) observed variables have linear dependency with each other. However, this is not applicable in every case. Non-linear relations are equally probable. In this series of posts, we will highlight some cases and ways to fit non-linear models using R.

First, we will generate some data for two variables x and y:

Now we will visualise the dataset in a scatter plot to see the non-linear relationship and also we will draw quadratic, cubic and quartic lines with red, green and yellow colors respectively: Modeling

Clearly, the relationship between x, y is exponential and can be described by the following mathematical form: In order to built a model that will appropriately describe the above mathematical formula, we will use the function nls() as follows:

Inspecting the output of the summary() result, we can see that the value of the power is 3.047 ± 0.1188 and is highly significant. The magnitude of the standard error is a measure of uncertainty for the estimated value of the exponent.

Fitting the model obtained above and stored in nlmodel and plotting the lines we have the following graph: We can see that the fitted model is very close to the cubic model that we used to create the data with the additional noise.

Goodness of fit

To examine the goodness of fit of the model, we will calculate R squared, seen in a previous post for linear regression:

R squared is calculated at 0.9778 which is a very good result highlighting the overall good performance of the model.