Least squares linear regression when squares have to do with elasticity?
1 次查看(过去 30 天)
显示 更早的评论
How can I calculate a least squares linear regression when squares have to do with elasticity?
Say in an ordinary least squares regression, a square distance from one point to the regression line is ydelta^2. I want the same ydelta distance to more important for some points than for others depending on elasticity functions for each points.
Is it possible to create this type of regression using a matlab formula? I am not a mathematician by trade.
0 个评论
回答(1 个)
Richard Willey
2012-4-5
Here's a simple example using the new regression functions in the 12a release. All you need to do is pass the appropriate weight vector in to the LinearModel function.
% Generate some data
X = 10 * rand(100,1);
Y = 5 + 3*X + randn(100,1);
% Assume a weight vector
temp = linspace(1, 50, 50);
temp = temp';
Weight_Vector = vertcat(temp, flipud(temp))
% Perform your regression
myFit = LinearModel.fit(X,Y, 'Weights', Weight_Vector)
plot(myFit)
FWIW, you can also pass weight vectors in to other regression functions, so if you're easier earlier versions of the Tbx you should be fine.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!