I hope this code gives a rough Idea of what I am trying to do, can someone tell me how I've gone about using manipulate in the wrong way and how I might look to restructure this existing code?
What I require it to do is allow me to manipulate the plain with the sliders and display the change graphicaly, I then want the values to directly effect what the sum of the residuals would be if they were to extend down to the manipulated plane, I also want to display that RSS and have it change as the sliders move.
I also cant find a bug that is not allowing the code to find the file regression.xls
The manipulate header
manipulate [
Body of the code
model = z /. Solve[a x + b y + c z + d == 0, z][[1]];
(-d - a x - b y)/c
(*get data*)
data = Import["RegressionExample.xls"][[1]] // Rest;
(*and header*)
header = Import["RegressionExample.xls"][[1]] // First
{"Adverts", "Airplay", "Sales"}
(*fit the data to the model*)
fit = NonlinearModelFit[data, model, {a, b, c, d}, {x, y}]
NonlinearModelFit::fitd :
"First argument \!\(data\) in NonlinearModelFit is not a list \
or a rectangular array. \!\(\*ButtonBox[\">>\", \
ButtonStyle->\"Link\", ButtonFrame->None, \
ButtonData:>\"paclet:ref/NonlinearModelFit\", ButtonNote -> \
\"NonlinearModelFit::fitd\"]\)"
FittedModel[
0.000927139168578378` (44355.63156634302` +
93.71519296640882` x + 3870.819045915761` y)]
FittedModel[
0.000927139168578378` (44355.63156634302` +
93.71519296640882` x + 3870.819045915761` y)]
(*sum of squared residuals*)
sumOfSquaredResiduals = fit["FitResiduals"] // Norm
693.1292063621133`
(*range for plotting*)
{advertsMin, advertsMax} = {Min[#], Max[#]} &@data[[All, 1]]
{9.1`, 2271.86`}
{airplayMin, airplayMax} = {Min[#], Max[#]} &@data[[All, 2]]
{0.`, 63.`}
(*make the plots separately then combine*)
(*best fit plane*)
bestFitPlanePlot =
Plot3D[fit[x, y], {x, advertsMin, advertsMax}, {y, airplayMin,
airplayMax}, PlotStyle -> {Blue, Opacity[.2]}];
(*original data*)
dataPlot =
ListPointPlot3D[data, PlotStyle -> Directive[Red, PointSize[.015]]];
(*make the drop lines*)
lines = Line[{#, {#[[1]], #[[2]], fit[#[[1]], #[[2]]]}}] & /@ data;
(*plot them*)
linePlot = Graphics3D[lines];
The Manipulate footer
, {a, -5, 5}, {b, -5, 5}, {c, -5, 5}, {d, -5, 5}]