-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathChapter.11.5.R
More file actions
31 lines (25 loc) · 794 Bytes
/
Chapter.11.5.R
File metadata and controls
31 lines (25 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#######################################################
# R script for 11.5 A Robust Regression Model
#######################################################
require(arm)
require(LearnBayes)
data(election)
attach(election)
y=sqrt(buchanan)
x=sqrt(perot)
N=length(y)
data=list("N","y","x")
inits = function() {list(b=c(0,0),tau=1)}
parameters <- c("tau","lam","b")
robust.sim <- bugs (data, inits, parameters, "robust.bug", n.chains=3, n.iter=1000)
print(robust.sim)
attach.bugs(robust.sim)
xo=seq(18,196,2)
X0=cbind(1,xo)
meanresponse=b%*%t(X0)
meanp=apply(meanresponse,2,quantile,c(.05,.5,.95))
plot(sqrt(perot),sqrt(buchanan))
lines(xo,meanp[2,])
lines(xo,meanp[1,],lty=2)
lines(xo,meanp[3,],lty=2)
#######################################################