1
$\begingroup$

I am using LinearModelFit to estimate four alternative model specifications on a small sample of 12 observations.

The models I'm using are

  1. ordinary linear model: $y=c+d_1D_1+d_2D_2+bx+k(x D_2)$
  2. log-linear model: $log(y)=c+d_1D_1+d_2D_2+bx+k(x D_2)$
  3. lin-log model: $y=c+d_1D_1+d_2D_2+blog(x)+k(log(x) D_2)$

and

  1. log-log model: $log(y)=c+d_1D_1+d_2D_2+blog(x)+k(log(x) D_2)$

The $D_j$'s are indicator variables and $y$ has its first two entries equal to zero, which poses a problem in the estimation of model specifications 2 and 4 ($log(0)\rightarrow-\infty$); to proceed with the estimation procedure, I simply replace the leading zeroes with $-1000$, when appropriate.

After comparing the output from LinearModelFit to that of another software, I realized that the estimated models 1 and 2 produced the same results (estimated parameters, standard errors, p-values) and differed in the values of $R^2$, adjusted $R^2$ and $AIC$ (Akaike info crit).

On the other hand, the output for models 3 and 4 were completely different between the two software.

Of all the observed discrepancies, I know that the values of $AIC$ can be attributed to different scaling used on different platforms; what seems troubling is the discrepancies observed in the rest reported values.

I reproduce the output from LinearModelFit along with the data used in the end notes; also, I include a sample script and accompanying data and output from the other software I used.

I am confused and I would like some help troubleshooting this problem. Up until now, I had no reason to consider either software as more 'reliable', so I don't know where to start.

Please note, I have also tested slightly different specifications of LinearModelFit (eg, switched IncludeConstantBasis on/off with the appropriately required change in input data) and done analogous changes in the other software; the results did not change; the discrepancies persisted.


End notes

(* function used to extract information from LinearModelFit output *)
info=Grid[{#[{"ParameterTable"}], {"RSquared", "AdjustedRSquared", "AIC"} -> #[{"RSquared", "AdjustedRSquared", "AIC"}] // Thread // Riffle[#, Null] & // Row // List, #[{"ANOVATable"}]} // Riffle[#, {{Null}}] &, Alignment -> Left]&

model 1

table=Uncompress["1:eJxTTMoPSuNlYGAoZgESPpnFJWmsyLxiEC85Pw/IYgKyXAwhlFExI5CqAJOVqDoyQWIQAogZimbNBILImQ5gHjalDDD1RevcH1aJNEwmRqkISC3LRIfML4yElO6Qa30dmFDnkHmHlZBSYxBYXOaQuYObkFKgmTvkcvMcMgvECSmN6T/0VeNMgUOmgDoepQzwEHjXQ8BbYKVBIH9drCTgLYSpdsUEvMUA99bdTALeAitNA4G+HIi3ANOjdlY="];
data=Rest[table];
xs={const, D1, D2, x};
fs={const, D1, D2, x, D2 x};
lmf=LinearModelFit[data, fs, xs, IncludeConstantBasis -> False];
info[lmf]

Blockquote

Eviews output

Blockquote

model 2

table=Uncompress["1:eJxTTMoPSuNlYGAoZgESPpnFJWmsyLxiEC85Pw/IYgKyXAwhlFExI5CqAJOVqDqKGMDggz06g4GhaNZMIIic6RBkD+TpGhoYGOgZ4AGGxkDC2MLS3DjB0FTP0tTEFMg2NzC0BOo0w28r0DK4yDr3h1UiDZPpbKsIyFqWiQ5FSTs2WB66LeFAvNYdcq2vAxPqHIpUf0bf2OMgS4JWYxBYXOZQZLhAdo4TswIJWoF27pDLzXMouuDMe0YtTZEErTH9h75qnClwKBIL3bp7Y7YSsVqBDHDkvOshOZiAjCBQOF2sJDmYYLbaFZMcTEAGOJjuZpIcTEBGGgj05SCCCQAessDY"];
data=Rest[table];
xs={const, D1, D2, x};
fs={const, D1, D2, x, D2 x};
lmf=LinearModelFit[data, fs, xs, IncludeConstantBasis -> False];
info[lmf]

enter image description here

Eviews output

enter image description here

model 3

table=Uncompress["1:eJxTTMoPSuNlYGAoZgESPpnFJWmsyLxiEC85Pw/IYgKyXAwhlFExI5CqAJOVqDqKGMDggz06g4GhaF9b3Gn+ibIOcBH8WoE64CK/F4gcz2qRIUfrtK/h17/+kIZqdah3IF5rQf11px37JKBaC6aToDXFZuGP2RPFYVqXk6B15sQHbPN/icK0bidB68PdnhxCCWJQrR2HidUKZLhP6djXE0R6MAEZm+0KzvpJkB5MQMbx74vkLV+LkRxMQEbQXiUbpxDSgwlkq/50p9U7RRHBBACX3ZNg"];
data=Rest[table];
xs={const, D1, D2, x};
fs={const, D1, D2, Log[x], D2 Log[x]};
lmf=LinearModelFit[data, fs, xs, IncludeConstantBasis -> False];
info[lmf]

enter image description here

Eviews output

enter image description here

model 4

table=Uncompress["1:eJxTTMoPSuNlYGAoZgESPpnFJWmsyLxiEC85Pw/IYgKyXAwhlFExI5CqAJOVqDqKGMDggz06g4GhaF9b3Gn+ibIOQfZAnq6hgYGBngEeYGgMJIwtLM2NEwxN9SxNTUyBbHMDQ0ugTjP8tgItg4v8XiByPKtFhs62Tvsafv3rD2mHoqQdGywP3ZZwIF5rQf11px37JByKVH9G39jjIEuC1hSbhT9mTxR3KDJcIDvHiVmBBK0zJz5gm/9L1KHogjPvGbU0RRK0PtztySGUIOZQJBa6dffGbCVitQIZ7lM69vUEkR5MQMZmu4KzfhKkBxOQcfz7InnL12IkBxOQEbRXycYphPRgAtmqP91p9U5RRDABAAErv1g="];
data=Rest[table];
xs={const, D1, D2, x};
fs={const, D1, D2, Log[x], D2 Log[x]};
lmf=LinearModelFit[data, fs, xs, IncludeConstantBasis -> False];
info[lmf]

enter image description here

Eviews output

enter image description here

This is a link to a zip file containing files 'eviews_data.csv' and 'replicate.prg'. Extract both files at a directory of your choosing; to run 'replicate.prg' please edit the first command by inserting the full path to file 'eviews_data.csv'.

$\endgroup$
10
  • $\begingroup$ Just looking at Model 3, the statistical package R gives the same values as Mathematica. You might want to try dividing the dependent variable by 1,000 and run the Eviews analysis again. $\endgroup$
    – JimB
    Commented Mar 8, 2018 at 16:21
  • $\begingroup$ I know this is not directly related to your concern about the differences in the results but...(1) Fitting 6 parameters with just 12 data points is likely not going to be very reliable, (2) Plugging in -1,000 for the log of zero is not a standard recommendation, and (3) Wanting to perform model selection on top of only having 12 observations with 6 parameters is expecting a bit too much. $\endgroup$
    – JimB
    Commented Mar 8, 2018 at 16:28
  • $\begingroup$ @JimB thanks for running the numbers; wouldn't scaling y by 0.001 simply scale the coefs proportionately? 1) I know 2) I kinda know; also what would be considered 'standard practice' in such a situation (drop the zeroes, interpolate them-somehow-in place, other choice ?) 3) I wasn't doing model-selection; I started from model 4 just to get a rough point estimate of the elasticity; usually, I cross-validate my results-that's how I figured out there was something wrong $\endgroup$
    – user42582
    Commented Mar 8, 2018 at 18:26
  • $\begingroup$ on a related note, model 4 in Eviews is probably correct because doing the calculations by hand yields an elasticity of -1.05 which is 'close' to -1.885-all things considered; I can understand that it's possible to get the coefs wrong but how can you get the $R^2$ wrong, is beyond me, hence the post $\endgroup$
    – user42582
    Commented Mar 8, 2018 at 18:26
  • 4
    $\begingroup$ I'm voting to close this question as off-topic because of a mistake by the OP. In the Mathematica code the Log is taken not once but twice for the variable labeled x. That is why the differences occur among the results from different packages. That issue would have been more readily evident if the short dataset was not shown in just compressed form. $\endgroup$
    – JimB
    Commented Mar 8, 2018 at 20:45

1 Answer 1

7
+50
$\begingroup$

This question should be closed because of a mistake by the OP. In the Mathematica code the Log is taken not once but twice. That is why the differences occur among the results from different packages. That issue would have been more readily evident if the data was not shown in just compressed form.

For Model 2 the data has the original value of x:

{{1., 1., 0., 1622.4, -1000.0}, {1., 0., 1., 1248.02, -1000.0},
 {1., 0., 1., 1089.12, 6.21461}, {1., 0., 1., 486.02, 7.31322}, 
 {1., 0., 1., 362.2, 8.00637}, {1., 0., 1., 243.41, 8.69951},
 {1., 0., 1., 268.76, 9.21034}, {1., 0., 0., 925.76, 6.21461}, 
 {1., 0., 0., 413.12, 7.31322}, {1., 0., 0., 307.88, 8.00637}, 
 {1., 0., 0., 206.91, 8.69951}, {1., 0., 0., 228.45, 9.21034}}

For Model 4 the value of x is now Log[x]:

{{1., 1., 0., 7.39166, -1000.0}, {1., 0., 1., 7.12931, -1000.0}, 
 {1., 0., 1., 6.99313, 6.21461}, {1., 0., 1., 6.18625, 7.31322},
 {1., 0., 1., 5.8922, 8.00637}, {1., 0., 1., 5.49475, 8.69951}, 
 {1., 0., 1., 5.59382, 9.21034}, {1., 0., 0., 6.83062, 6.21461}, 
 {1., 0., 0., 6.02374, 7.31322}, {1., 0., 0., 5.72971, 8.00637}, 
 {1., 0., 0., 5.33228, 8.69951}, {1., 0., 0., 5.43132, 9.21034}}

But Model 4 takes the log again:

xs={const, D1, D2, x};
fs={const, D1, D2, Log[x], D2 Log[x]};
lmf=LinearModelFit[data, fs, xs, IncludeConstantBasis -> False];

That is why the results differ between Mathematica and Eviews (and R and SAS).

$\endgroup$

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