Description Usage Arguments Value Author(s) Examples
Visualise fitted regression and data with uncertainty (either a polygon or spaghetti plot)
1 2 3 |
xdata |
The predictor. A numeric vector. |
ydata |
The response variable. A numeric vector (can be a binary variable). |
betamat |
A numeric matrix of nsims x nparams dimensions with the posterior values of the model parameters, e.g. as retrieved from model$BUGSoutput$sims.matrix[,c("intercept", "slope")] |
predmat |
A numeric matrix with ncol=nparams, containing the values of the covariates that should be used for the plot, including the intercept. The order of the covariate columns should be the same as the parameter columns in betamat. |
predcol |
A number telling which column in predmat represents the covariate to plot. |
plot.unc |
Logical. Plot uncertainty or just the average fitted response? |
spag |
Logical. Make spaghetti plot? If False, and plot.unc=T, a shaded polygon is drawn instead |
colour |
Colour of the regression lines. If missing, it is taken from palette "Set1" in RColorBrewer. |
alpha.spag |
Alpha multiplier. A number between 0 and 1 (default=1) to adjust the transparency of the uncertainty lines in the spaghetti plot. |
lwd.spag |
Line width (lwd) of every line in the spaghetti plot. Together with alpha.spag, define the degree of shadeness of the spaghetty plot |
alpha.polyg |
Alpha parameter (values between 0 and 255) for setting the transparency of the shaded polygon. |
add |
Logical. Add another regression line to an existing plot? |
... |
Further parameters to pass to plot. See |
A plot
Paco, based on code by Lucas Leeman (see http://andrewgelman.com/2012/08/graphs-showing-regression-uncertainty-the-code/)
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 | ### LINEAR REGRESSION ###
# First generate some data
interc <- 0.6
slope <- 0.2
sigma <- 0.1
x <- seq(from=1, to=10, length.out=100)
y <- rnorm(100, interc + slope*x, sigma)
xdata <- x
ydata <- y
nsims <- 200
interc.post <- rnorm(nsims, interc, 0.05)
slope.post <- rnorm(nsims, slope, 0.01)
betamat <- cbind(interc.post, slope.post)
predmat <- cbind(rep(1,length(xdata)), xdata)
#plotReg(xdata, ydata, betamat, predmat)
#plotReg(xdata, ydata, betamat, predmat, spag=F)
#plotReg(xdata, ydata, betamat, predmat, plot.unc=F)
#plotReg(xdata, ydata, betamat, predmat, main="My regression", xlab="My x") # including graphical parameters
#plotReg(xdata, ydata, betamat, predmat, colour="green") # specifying colour
## Add another regression lines to the plot
### LOGISTIC REGRESSION ###
# Generate some data
x <- seq(1:1000)
yhat <- plogis(0.2 + 0.003*x) # inverse logit
y <- rbinom(1000, 1, yhat)
# Fit model and get predicted probabilities
model <- glm(y~x, family="binomial")
ypred <- predict(model, type="response")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.