plot.blm: Plot of a Bayesian Linear Model Fit

Description Usage Arguments Details Examples

View source: R/blm_plots.R

Description

Plots the blm object along with the MAP fit line and quantiles for the fit.

Usage

1
2
3
4
5
6
## S3 method for class 'blm'
plot(x, explanatory = NULL, show_blm_interval = TRUE,
  blm_interval_level = 0.95, expand_fit = TRUE, blm_col = "blue",
  blm_map_lty = 1, blm_interval_lty = 2, show_lm = TRUE, lm_col = "red",
  lm_lty = 2, caption = "Bayesian lm fit", add_formula = TRUE,
  show_legend = TRUE, legend_parm = NULL, xlab, ylab, ...)

Arguments

x

a blm object.

explanatory

name of the explanatory variable to be plotted on the x axis.

show_blm_interval

display interval of the blm fitted values?

blm_interval_level

level for the interval of the distribution of response to be shown.

expand_fit

expand fit lines to the limits of the plot?

blm_col

color for the blm fit lines.

blm_map_lty

linetype for the blm MAP estimate line.

blm_interval_lty

linetype for the blm quantiles line.

show_lm

display the regular lm fit on the plot?

lm_col

color for the lm fit line.

lm_lty

linetype for the lm fit line.

caption

title to be added to the plot.

add_formula

append formula to the caption.

show_legend

add a legend for the fit lines to the plot?

legend_parm

list of additional arguments for the legend.

xlab

label for the x axis.

ylab

label for the y axis.

...

other arguments passed to plot.

Details

Plots the data points used to create the blm object, together with the blm fit, 95 (frequentist) lm fit.

Examples

 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
x <- rnorm(100)
b <- 1.3
w0 <- 0.2 ; w1 <- 3 ; w2 <- 10

y <- rnorm(100, mean = w0 + w1 * x + w2 *sin(x), sd = sqrt(1/b))
model <- blm(y ~ x + sin(x), prior = NULL, beta = b, 
               data = data.frame(x=x, y=y)) 

##need to do more in case of complex model that does not contain a term 'x'
y <- rnorm(100, mean = w0 + w1 * cos(x), sd = sqrt(1/b))
model <- blm(y ~ cos(x), prior = NULL, beta = b, 
             data = data.frame(x=x, y=y))

## Not run: 
#plots y~cos(x) on the x-axis and this does probably not produce the plot we
want.
plot(model, xlim=c(-10,10))

## End(Not run)

#one can specify that we want 'x' and not 'cos(x)' on the x axis by providing
#the name of the explanatory and we get the correct results 
plot(model, explanatory='x', xlim=c(-10,10))


#response and explanatory names do not matter
z_not_x <- rnorm(100)
b <- 1.3
w0 <- 0.2 ; w1 <- 3 ; w2 <- 10

means = w0 + w1 * z_not_x + w2 *sin(z_not_x)
v_not_y <- rnorm(100, means, sd = sqrt(1/b))
formula <- v_not_y ~ z_not_x + sin(z_not_x)
model <- blm(formula, prior = NULL, beta = b, 
               data = data.frame(z_not_x=z_not_x, v_not_y=v_not_y))

plot(model)

#customizing the plot, almost anything is possible
plot(model, col='purple', pch=19, cex=.3, type='p')
plot(model, col='purple', pch=19, cex=.3, xlim=c(-10,10), ylim=c(-50,50))
plot(model, col='purple', pch=19, cex=.3, xlim=c(-10,10), ylim=c(-50,50), 
     expand_fit=FALSE)

#customizing the plot lines
 plot(model, show_lm=FALSE)
 plot(model, show_lm=FALSE, blm_interval_lty=3, blm_col='red')
 plot(model, lm_col='blue', lm_lty=4, blm_interval_lty=3, blm_col='red')
 
 plot(model, show_legend=FALSE)
 plot(model, legend_parm=list(x='bottomright', cex=.5))
 

manschmi/blm documentation built on May 21, 2019, 11:25 a.m.