matlab exclude,Exclude data from fit

Load the vote counts and county names for the state of Florida from the 2000 U.S. presidential election.

load flvote2k

Use the vote counts for the two major party candidates, Bush and Gore, as predictors for the vote counts for the third-party candidate Buchanan, and plot the scatters:

plot(bush,buchanan,'rs')

hold on

plot(gore,buchanan,'bo')

legend('Bush data','Gore data')

a14ae1f9a828634a89702a610ac6b849.png

Assume a model where a fixed proportion of Bush or Gore voters choose to vote for Buchanan.

f = fittype({'x'})

f =

Linear model:

f(a,x) = a*x

Exclude the data from absentee voters, who did not use the controversial “butterfly” ballot.

nobutterfly = strcmp(counties,'Absentee Ballots');

Perform a bisquare weights robust fit of the model to the two data sets, excluding absentee voters.

bushfit = fit(bush,buchanan,f,'Exclude',nobutterfly,'Robust','on');

gorefit = fit(gore,buchanan,f,'Exclude',nobutterfly,'Robust','on');

Robust fits give outliers a low weight, so large residuals from a robust fit can be used to identify the outliers.

figure

plot(bushfit,bush,buchanan,'rs','residuals')

hold on

plot(gorefit,gore,buchanan,'bo','residuals')

c170e8f5836f8e8f5946282fa2f8d3a4.png

Calculate the residuals.

bushres = buchanan - feval(bushfit,bush);

goreres = buchanan - feval(gorefit,gore);

Identify large residuals as those outside the range [-500 500].

bushoutliers = excludedata(bush,bushres,'range',[-500 500]);

goreoutliers = excludedata(gore,goreres,'range',[-500 500]);

Display the counties corresponding to the outliers. Miami-Dade and Broward counties correspond to the largest predictor values. Palm Beach county, the only county in the state to use the “butterfly” ballot, corresponds to the largest residual values.

counties(bushoutliers)

ans = 2x1 cell

{'Miami-Dade'}

{'Palm Beach'}

counties(goreoutliers)

ans = 3x1 cell

{'Broward' }

{'Miami-Dade'}

{'Palm Beach'}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值