1
$\begingroup$

For the Fit function we can define NormFunction with Huber penalty.

Fit[data, {1, x}, x, NormFunction -> {"HuberPenalty", \[Alpha]}]

What is $\alpha$ here? Is it the Huber loss threshold $\delta$ for standardized dependent variable?

It is very slow for 2000 points? Is this a bug? The wrong algorithm is chosen?

ClearAll[x, n, xs, data, lm];
dist = TruncatedDistribution[{0, Infinity}, 
   MixtureDistribution[{1, 2}, {NormalDistribution[0, 1/2], 
     NormalDistribution[2, 1/2]}]];
Plot[PDF[dist, x], {x, -1, 5}, PlotRange -> Full, PlotStyle -> Red]
n = 2000;
data = RandomVariate[dist, n];
dataMean = Mean[data];
xd = RandomReal[{0, 10}, n];
data = Transpose[{xd, data}];
lm = Fit[data, {1, x}, x, NormFunction -> {"HuberPenalty", 0.01}];
Show[ListPlot[data],
 Plot[lm[x], {x, 0, 10}, PlotStyle -> Red],
 ListLinePlot[{{0, dataMean}, {10, dataMean}}]]
$\endgroup$

Your Answer

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

Browse other questions tagged or ask your own question.