How do you compare linear model vs non-linear (nls) model in R? I am trying to model some data, and as part of the modeling, I tried using a linear model (using the lm function) and a non-linear model (using the nls) function.

*

*Model 1: a linear model which has degrees of freedom (df), (AIC) = 2, 2130


*Model 2:  a non-linear model which has df, AIC= 4, 2128.


*Model 3: I took model 2 above and fixed a parameter to the estimated value in model 2. It resulted in df, AIC= 3, 2126.
My question is: how to select the best fitting model from the above candidate models? Can I simply use AIC (lower is better) and therefore select model 3?
 A: The question is indeed rather theoretical. What is the best theoretical model by construction (i.e. how do the variables connect to each other? Is the theoretical dependence of linear or non-linear nature?). 
However, if that is not possible, I suggest to compare the models using BIC and AIC as well and select some model inbetween those two. From my personal experience AIC is better for predictions and BIC better for fitting (explanatory).
A: You will find unending debates on the question. There is no good answer on that question.  Generally, people tend to prefer BIC rather than AIC. BIC selects more parcimonious models because the penalty for the number of parameters is higher.
If you are more interested in predictions, you might use other performance criterion. Especially root mean square error (RMSE).
I think you will find many interesting debates on this question on CrossValidated.
A: If you are interested in predictions:
The MAPE function in R, or mean absolute percentage error (MAPE), is a measure of prediction accuracy of a forecasting method in statistics.
install.packages("MLmetrics") 
library(MLmetrics)
MAPE(predict(model),real_values)

