全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件
8223 11
2006-04-21

请问如何在Matlab里实现lowess (locally weighted scatterplot smoothing) regression.

是否有软件直接可以实现呢?

多谢!

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2006-4-22 01:01:00

For SAS:

SAS Macro Programs for Statistical Graphics: LOWESS

LOWESS macro ( get lowess.sas)

The LOWESS macro performs robust, locally weighted scatterplot smoothing as described in "Section 4.4.2". The data and the smoothed curve are plotted if PLOT=YES is specified. The smoothed response variable, residuals, and observation weights are returned in the output data set named by the OUT= parameter. An optional output ANNOTATE= data set can also be produced, which may be used to apply the lowess smoothing in a more complex plotting application.

As of Version 2.1, the LOWESS macro will use PROC LOESS if running under Version 7 of the SAS System. This makes the macro much faster, particularly for large data sets. For use with SAS 6.12 or earlier, use the STEP= parameter to control the number of data points at which the local regressions are computed.

[此贴子已经被作者于2006-4-22 1:24:03编辑过]

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2006-4-22 01:01:00

Continued:

Parameters

DATA=_LAST_
Name of the input data set.
X = X
Name of the independent (X) variable.
Y = Y
Name of the dependent (Y) variable to be smoothed.
ID=
Name of an optional character variable to identify observations.
OUT=SMOOTH
Name of the output data set. The output data set contains the X=, Y=, and ID= variables plus the variables _YHAT_, _RESID_, and _WEIGHT_. _YHAT_ is the smoothed value of the Y= variable, _RESID_ is the residual, and _WEIGHT_ is the combined weight for that observation in the final iteration.
F = .50
Lowess window width, the fraction of the observtions used in each locally-weighted regression. A larger window width makes the curve smoother, but may lead to lack of fit. Values of F > 1 are allowed.
P = 1
Degree of the locally-weighted regressions. P=1 gives linear fits, appropriate when the data do not have several peaks and valleys; P=2 gives quadratic fits, which are useful when they do.
ITER=2
Total number of iterations.
ROBUST=1
Specifies whether to perform robustness re-weightings, which decrease the weights for observations with large residuals in the next iteration. Set ROBUST=0 to suppress the robust calculations. For binary dependent variables, the robustness step is usually not performed.
CLM=
[Version 7+ only] Specifies the significance level for confidence intervals about the smoothed curve. Use CLM=0.05 for 95% confidence intervals.
STEP=1
Step for successive X values. By default, the macro performs the locally-weighted regression at each X, which can be computationally intensive for moderately large data sets. Setting STEP > 1 causes the macro to perform the regression at every STEP-th value of the index i, and to use predicted values from that regression for intermediate points. It is recommended to specify a STEP value at least n/100 for moderate to large sized datasets.
PLOT=NO
Specifying PLOT=YES, draws both a printer plot and a high-resolution plot. You may wish to change the default values of the PLOT, GPLOT or PPLOT options to suit your taste.
GPLOT=NO
Draw the plot? If you specify PLOT=YES, a high-resolution plot is drawn by the macro.
PPLOT=NO
Draw a printer plot? If you specify PPLOT=YES, a printer plot is drawn by the macro.
SYMBOL=CIRCLE
Plotting symbol used for points
HTEXT=1.5
Height for axis labels and values
HSYM=1.5
Height for point symbols
COLORS=BLACK RED
colors for points and smooth curve
LINE=1
Line style for the smooth curve
HAXIS=
The name of an AXIS statements for the horizontal axis
VAXIS=
The name of an AXIS statements for the vertical axis
OUTANNO=
Name of output ANNOTATE= dataset which draws the smoothed lowess curve. This dataset is produced only if the OUTANNO= name is specified.
IN=
Name of an optional input ANNOTATE= data set, which is concatenated to the OUTANNO= data set.
NAME=LOWESS
The name assigned to the graph in the graphic catalog.

Missing data

Any observations with missing data on the X or Y variables are removed before finding the lowess fit.

Usage Note

Under some older versions of the SAS System, it may be neccessary to add the option WORKSIZE=100 to the PROC IML statement.

Example

This example plots gas mileage (MPG) vs weight, with a smoothed lowess curve showing a (slight) nonlinear dependence of mileage on weight. The plot is drawn by the macro from the OUT=SMOOTH data set. An output ANNOTATE= data set is also produced.
title 'Auto data with lowess smoothing';
%include data(auto);
%include macros(lowess);

%lowess(data=auto,out=smooth, x=weight, y=mpg,
id=model, htext=2,
f=.4, plot=YES,
colors=blue red, outanno=lowess);

[此贴子已经被作者于2006-4-22 1:11:31编辑过]

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2006-4-22 01:06:00

For Matlab:

mslowess
Smooth mass spectrum using nonparametric method

Syntax
Yout = mslowess(MZ, Y, 'PropertyName', PropertyValue...)
mslowess(..., 'Order', OrderValue)
mslowess(..., 'Span', SpanValue)
mslowess(..., 'Kernel', KernelValue)
mslowess(..., 'RobustIterations', RobustIterationsValue)
mslowess(..., 'ShowPlot', ShowPlotValue)


Arguments
MZ
Mass/charge vector with the range of ions in the spectra.

Y
Ion intensity vector with the same length as the mass/charge vector (MZ). Y can also be a matrix with several spectra that share the same mass/charge (MZ) range.


Description
Yout = mslowess(MZ, Y, 'PropertyName', PropertyValue...) smoothes a mass spectrum (Y) using a locally weighted linear regression (lowess) method with a default span of 10 samples.

Note 1) mslowess assumes that a mass/charge vector (MZ) might not be uniformly spaced. Therefore, the sliding window for smoothing is centered using the closest samples in terms of the MZ value and not in terms of the MZ indices.

2) When the vector MZ does not have repeated values or NaNs, the algorithm is approximately twice as fast.


mslowess(..., 'Order', OrderValue) specifies the order (OrderValue) of the Lowess smoother. Enter 1 (linear polynomial fit or Lowess), 2 (quadratic polynomial fit or Loess), or 0 (equivalent to a weighted local mean estimator and presumably faster because only a mean computation is performed instead of a least squares regression). The default value is 1.

Note The MATLAB Curve Fitting Toolbox also refers to Lowess smoothing of order 2 as Loess smoothing.

mslowess(..., 'Span', SpanValue) specifies the window size for the smoothing kernel. If SpanValue is greater than 1, the window is equal to SpanValue number of samples independent of the mass/charge vector (MZ). The default value is 10 samples. Higher values will smooth the signal more at the expense of computation time. If SpanValue is less than 1, the window size is taken to be a fraction of the number of points in the data. For example, when SpanValue is 0.005, the window size is equal to 0.50% of the number of points in MZ.

mslowess(..., 'Kernel', KernelValue) selects the function (KernelValue) for weighting the observed ion intensities. Samples close to the MZ location being smoothed have the most weight in determining the estimate. Enter

'tricubic' (default) (1 - (dist/dmax).^3).^3
'gaussian' exp(-(2*dist/dmax).^2)
'linear' 1-dist/dmaxmslowess(..., 'RobustIterations', RobustIterationsValue) specifies the number of iterations (RobustValue) for a robust fit. If RobustIterationsValue is 0 (default), no robust fit is performed. For robust smoothing, small residual values at every span are outweighed to improve the new estimate. 1 or 2 robust iterations are usually adequate while, larger values might be computationally expensive.

Note For a uniformly spaced MZ vector, a nonrobust smoothing with Order equal to 0 is equivalent to filtering the signal with the kernel vector.


mslowess(..., 'ShowPlot', ShowPlotValue)plots the smoothed spectrum over the original spectrum. When mslowess is called without output arguments, the spectra are plotted unless ShowPlotValue is false. When ShowPlotValue is true, only the first spectrum in Y is plotted. ShowPlotValue can also contain an index to one of the spectra in Y.

Example
Load sample data.

load sample_lo_resSmooth spectrum and draw figure with unsmoothed and smoothed spectra.

YS = mslowess(MZ_lo_res,Y_lo_res(:,1),'Showplot',true);

[此贴子已经被作者于2006-4-22 1:25:49编辑过]

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2006-4-22 01:12:00

For SPSS,

Somebody said: The locally weighted regression and scatterplot smoothing (LOWESS) technique was applied to allow the graphed data to reveal their own patterns; LOWESS is available as part of the SPSS software

[此贴子已经被作者于2006-4-22 1:24:56编辑过]

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2006-4-22 01:22:00

Applied Regression Analysis by John Fox:

SPSS will not allow the multiple regression lines to be placed on a single graph. Also, we do not know how to do a lowess non-parametric regression in SPSS.

[此贴子已经被作者于2006-4-22 1:23:00编辑过]

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群