Description Usage Arguments Details Value Note Author(s) References See Also Examples
View source: R/LinearErrorsInVariablesClass.R
Generates a linear errorsinvariables object.
1 2 3 4 5 6 7 8 9 10  leiv(formula, data, subset, prior = NULL,
n = NULL, cor = NULL, sdRatio = NULL, xMean = 0, yMean = 0,
probIntCalc = FALSE, level = 0.95, subdivisions = 100,
rel.tol = .Machine$double.eps^0.25, abs.tol = 0.1*rel.tol, ...)
## S4 method for signature 'leiv'
print(x, digits = max(3, getOption("digits")  3), ...)
## S4 method for signature 'leiv,missing'
plot(x, plotType = "density", xlim = NULL, ylim = NULL,
xlab = NULL, ylab = NULL, col = NULL, lwd = NULL, ...)

formula 
an optional object of class 
data 
an optional data frame (or object coercible by 
subset 
an optional vector specifying a subset of observations to be used in the fitting process. 
prior 
an optional object of class 
n 
an optional sample size (if 
cor, sdRatio 
optional sample correlation 
xMean, yMean 
optional sample means 
probIntCalc 
logical; if 
level 
the probability level requested (if 
subdivisions 
the maximum number of subintervals (see 
rel.tol 
the relative accuracy requested (see 
abs.tol 
the absolute accuracy requested (see 
x 
a 
digits 
controls formating of numeric objects. 
plotType 
specifies the type of plot; if 
xlim, ylim 
x limits 
xlab, ylab 
labels for the x and y axes of the plot. 
col, lwd 
color and width of plotted lines. 
... 
additional argument(s) for generic methods. 
Use leiv
to estimate the slope and intercept of a bivariate linear relationship when both variables are observed with error. The method is exact when the true values and the errors are normally distributed. The posterior density depends on the data only through the correlation coefficient and ratio of standard deviations; it is invariant to interchange and scaling of the coordinates.
leiv
returns an object of class "leiv"
with the following components:
slope 
the (posterior median) slope estimate. 
intercept 
the (maximum likelihood) intercept estimate. 
slopeInt 
the shortest (100* 
interceptInt 
the shortest (100* 
density 
the posterior probability density function. 
n 
the number of (x,y) pairs. 
cor 
the sample correlation 
sdRatio 
the ratio 
xMean 
the sample mean 
yMean 
the sample mean 
call 
the matched call. 
probIntCalc 
the logical probability interval request. 
level 
the probability level of the probability interval. 
x 
the x data. 
y 
the y data. 
Numerical integration is used to normalize the posterior density. When the data is nearly linear, normalization using the default tolerance parameters may fail. Specifying abs.tol = 1e6
(or smaller) may help, but expect a longer run time. In general, rel.tol
cannot be less than max(50*.Machine$double.eps, 0.5e28)
if abs.tol <= 0
. In addition, when using a sharply peaked leiv
object as a prior density, normalization may fail. In this case, an alternative is to first fit using the default Cauchy prior, then multiply by the appropriate ratio of prior densities and tackle the normalization outside of the leiv
environment.
David Leonard
Leonard, David. (2011). “Estimating a Bivariate Linear Relationship.” Bayesian Analysis, 6:727754. DOI:10.1214/11BA627.
Zellner, Arnold. (1971). An Introduction to Bayesian Inference in Econometrics, Chapter 5. John Wiley & Sons.
lm
for formula syntax; integrate
for control parameters.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23  ## generate artificial data
set.seed(1123)
n < 20
X < rnorm(n, mean=5, sd=4) # true x
x < X + rnorm(n, mean=0, sd=5) # observed x
Y < 2 + X # true y
y < Y + rnorm(n, mean=0, sd=3) # observed y
## fit with default options
fit < leiv(y ~ x)
print(fit)
plot(fit) # density plot
dev.new()
plot(fit,plotType="scatter")
## calculate a density to use as an informative prior density of
## the scale invariant slope in a subsequent fit
fit0 < leiv(n=10, cor=0.5, sdRatio=1.0)
print(fit0)
## refit the data using the informative prior density
fit1 < leiv(y ~ x, prior=fit0, abs.tol=1e6)
print(fit1)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.