1
$\begingroup$

I have been getting error messages in my attempt to estimate parameters in a non-linear function using nlminb function. The following is the code:

func=function(par,x){ 
    data[,1] ~ ((x[,5]*x[,4])^((par[1]-1)/par[1]) + ((x[,3]*x[,6])^((par[2]-1)/par[2])+ (x[,2]*x[,7])^((par[2]-1)/par[2]))^(((par[1]-1)/par[1])*(par[2]/(par[2]-1))))^(par[1]/(par[1]-1))
}
nlminb(start=c(0.8,0.6), func, x=data)

The data I have is a set of time series. The following is the error I am getting:

Warning messages:
1: In nlminb(start = c(0.8, 0.2), model, x = data) :
  NA/NaN function evaluation

The following is the data

1   103.84660   7695.040    124.8315    115.2998    1.0080483   1.001325    0.9938076   1
2   113.16377   7742.493    124.5868    116.2914    1.0052380   1.004880    1.0171624   2
3   110.24519   7797.469    124.4623    117.2707    0.9944189   1.011406    1.0281476   3
4   103.17992   7864.746    124.4574    118.2496    1.0179428   1.015610    1.0517229   4
5   122.83588   7902.960    124.5721    119.2821    1.0208074   1.019282    1.0735748   5
6   116.58633   7921.277    124.8066    120.2782    1.0090971   1.019724    1.0669756   6
7   98.73047    7947.280    125.1614    121.2992    1.0171887   1.024867    1.1092066   7
8   110.92299   7976.375    125.6375    122.3042    1.0084163   1.026991    1.1456070   8
9   118.06808   8003.961    126.2360    123.2945    1.0351463   1.031189    1.1499949   9
10  102.28658   8022.360    126.9587    124.3334    1.0292670   1.031507    1.1574415   10
11  92.99516    8045.384    127.8074    125.3624    1.0251884   1.035247    1.1869132   11
12  101.39479   8036.162    128.7846    126.4021    1.0479171   1.038441    1.2017964   12
13  101.30144   8020.789    129.6421    127.4284    1.0357224   1.039799    1.2341470   13
14  96.95292    8034.624    130.3773    128.4379    1.0399284   1.042869    1.2725077   14
15  106.64892   8063.858    130.9879    129.4655    1.0346895   1.043092    1.2802305   15
16  103.65601   8073.111    131.4721    130.5830    1.0294096   1.047213    1.3211646   16
17  107.57715   8122.403    131.8282    131.7203    1.0352389   1.048407    1.3464485   17
18  113.64242   8177.897    132.7665    132.8507    1.0494784   1.049540    1.3783562   18
19  120.05998   8233.438    134.2970    134.0168    1.0509931   1.050161    1.4049428   19
20  117.94485   8289.026    136.4372    135.0831    1.0475881   1.052968    1.4100514   20
21  125.46768   8261.399    139.2131    136.2520    1.0676247   1.054175    1.4409652   21
22  120.57292   8252.264    142.6594    137.2626    1.0688130   1.059272    1.4969188   22
23  121.85877   8260.101    145.5310    138.2797    1.0452529   1.058159    1.5132735   23
24  118.93148   8291.103    147.7873    139.3569    1.0653257   1.059835    1.5295049   24
25  117.74407   8320.588    149.3949    140.4136    1.0680230   1.062398    1.5748625   25
26  120.81597   8351.646    150.3290    141.4838    1.0791235   1.064557    1.6218405   26
27  117.08652   8422.914    150.5735    142.5232    1.0682042   1.064907    1.6616629   27
28  116.37610   8472.598    150.4380    143.7123    1.0616077   1.065997    1.6701485   28
29  119.92723   8390.855    149.9225    144.7475    1.0702911   1.066648    1.7159248   29
30  113.26243   8256.443    149.0300    145.7908    1.0611327   1.068071    1.7417198   30
31  115.85483   8155.983    147.7663    146.8241    1.0787689   1.070899    1.7752797   31
32  114.01433   8149.909    146.1400    147.8764    1.0899623   1.071713    1.8460021   32
33  121.58956   8185.661    145.4177    148.9278    1.0771952   1.074088    1.8647514   33
34  124.28517   8229.194    145.5807    149.9583    1.0801203   1.075055    1.9123212   34
35  123.83632   8314.625    146.6266    150.9679    1.0799208   1.078315    1.9214472   35
$\endgroup$
  • $\begingroup$ Try reparameterizing. Make parnew[1] = (par[1]-1)/par[1] . parnew[2] = (par[2]-1)/par[2] . Then use parnew[1], parnew[2] as your parameters to be estimated. You will still have the recirpocals of these in one place. Combine that with sensible lower and upper bounds on parnew[1] and parnew[2]. $\endgroup$ – Mark L. Stone May 5 '16 at 15:26
  • $\begingroup$ I tried this too, did not work :( $\endgroup$ – mr.rox May 5 '16 at 15:34
  • $\begingroup$ Anyhow, that's a whole heck of a lot of exponentiation. Do you have a good rationale for this function? $\endgroup$ – Mark L. Stone May 5 '16 at 15:35
  • $\begingroup$ This is a constant elasticity of substitution function used in economic analysis of input and output data. The parameters are basically elasticities of substitution between input factors. Theory suggests the parameters are positive and usually less than one. This study discusses the various non-linear estimation methods and algorithms: ftp.zew.de/pub/zew-docs/dp/dp12007.pdf Thanks $\endgroup$ – mr.rox May 5 '16 at 15:38
1
$\begingroup$

Its likely that while exploring parameter space the algorithm generates non-real numbers (by dividing by 0, taking the square root of a negative number, or something else). To avoid this consider setting the upper and lower bounds on your parameters using the upper and lower settings in the nlminb function. I would start with:

nlminb(start=c(0.8,0.6), lower=c(0, 0), upper=c(1000,1000), func, x=data)

However, if you provide example data I could test this more fully.

$\endgroup$
  • $\begingroup$ I tried using these, no success. I've now edited the original post to include the data set. Will you please have a look? Thanks. $\endgroup$ – mr.rox May 5 '16 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.