Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am trying to use the LinearModelFit function to obtain a linear regression of my 5 inputs for my single output. I have the input data:

    MasterDataInputs={{"payload", "travel_empty_time", "travel_loaded_time", 
  "net_loaded_lift", "idle_time"}, {16241., 89126., 81075., 7747., 
  84323.}, {2364., 10879., 10811., 1421., 12708.}, {4297., 22730., 
  24092., 373., 16606.}, {5494., 30667., 32297., 999., 
  20341.}, {3926., 22025., 20520., 3410., 23993.}, {6193., 31027., 
  28319., 4948., 30262.}, {5709., 27699., 25351., 1990., 
  26282.}, {2178., 13410., 14036., 1433., 12485.}, {3605., 18509., 
  17690., 2238., 12170.}, {5620., 28632., 24355., 3538., 
  27632.}, {4352., 25259., 28307., 2176., 16712.}, {12550., 59921., 
  59001., 3095., 58977.}, {5520., 30586., 26967., 4121., 
  17851.}, {3193., 19732., 19310., 2769., 15507.}, {9732., 56096., 
  57320., 8088., 45418.}, {4531., 23906., 30182., 3789., 
  18930.}, {4521., 27455., 26796., 3356., 21291.}, {4286., 25317., 
  27807., 2777., 15309.}, {4226., 24740., 31243., 3056., 
  20926.}, {3060., 20052., 22617., 2144., 12753.}, {4738., 28425., 
  24036., 4534., 24927.}, {7900., 46413., 47040., 4764., 
  37522.}, {6964., 41928., 36873., 3729., 32866.}, {19063., 99629., 
  102567., 4959., 70360.}, {5043., 30703., 28573., 2819., 
  23747.}, {8070., 43767., 41004., 2281., 33673.}, {4580., 25321., 
  25370., 2562., 21293.}, {7012., 47499., 38037., 6957., 
  35961.}, {1616., 8119., 7718., -18., 6468.}, {2853., 16548., 16089.,
   2572., 12738.}, {13729., 94984., 83507., 7410., 71171.}, {5644., 
  33104., 36720., 3420., 31578.}, {8280., 57066., 49212., 4818., 
  38604.}, {5620., 34289., 30598., 3970., 26980.}, {5881., 35405., 
  37019., 4177., 34324.}, {3364., 21765., 20473., 2613., 
  13166.}, {5174., 31533., 29321., 4872., 27182.}, {5435., 35767., 
  31029., 3773., 31672.}, {5880., 39594., 33352., 6140., 
  35198.}, {3814., 23659., 26286., 2724., 18484.}, {1271., 7350., 
  7163., 1319., 9607.}, {9463., 60296., 63248., 9054., 
  45353.}, {3243., 22832., 25124., 3451., 15275.}, {8022., 48725., 
  48224., 8829., 38922.}, {1805., 11246., 12426., 687., 9147.}}

and the outputs:

MasterDataOutput ={"fuel output", 2099.749899, 1384.120668, 1620.060306, 1755.348166, \
1595.189198, 1798.31186, 1722.579319, 1411.483751, 1537.460621, \
1730.932625, 1671.089154, 2010.22954, 1760.840169, 1536.90848, \
2126.08609, 1691.889546, 1688.623823, 1670.48431, 1681.022846, \
1549.985641, 1695.898173, 1979.419182, 1897.569649, 2280.36639, \
1732.712557, 1933.740813, 1666.700071, 1966.088623, 1304.244403, \
1480.054095, 2105.763533, 1799.491245, 2029.785039, 1793.720838, \
1825.476258, 1563.436693, 1761.070177, 1785.978395, 1854.485829, \
1628.997857, 1281.707381, 2152.698111, 1595.443235, 2061.991531, \
1366.867529}

I have tried the following after searching this forum and the help:

LinearModelFit[{MasterDataInputs[[2 ;;]], MasterDataOutput[[2 ;;]]}, 
  MasterDataInputs[[1]]] 

which resulted in an equation without a constant. I need a constant in my equation so I tried:

LinearModelFit[{MasterDataInputs[[2 ;;]], MasterDataOutput[[2 ;;]]}, 
  MasterDataInputs[[1]], IncludeConstantBasis -> True] // Normal

which still gives me no constant even though the help says it should. I have also tried the below:

LinearModelFit[{MasterDataInputs[[2 ;;]], MasterDataOutput[[2 ;;]]}, 
  IncludeConstantBasis -> True] // Normal

and all variation without the //Normal at the end. Please will someone help, I need a linear regression equation with a constant term.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I prefer the more general function; you can do :

data = Transpose[
   Join[Transpose[
     MasterDataInputs[[2 ;;]]], {MasterDataOutput[[2 ;;]]}]][[1 ;; 2]] ;

nlm = NonlinearModelFit[data, 
  a0 + a1 x1 + a2 x2 + a3 x3 + a4 x4 + a5 x5, {a0, a1, a2, a3, a4, 
   a5}, {x1, x2, x3, x4, x5}]

nlm // Normal
(* 1254.18 +0.0102011 x1+0.00115933 x2+0.00164517 x3+0.0340745 x4+0.00212529 x5 *)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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