Two-stage measurement error

measurement.error(
  model1,
  formula,
  data = parent.frame(),
  predictfun = function(mu, var, data, ...) mu[, 1]^2 + var[1],
  id1,
  id2,
  ...
)

Arguments

model1

Stage 1 model

formula

Formula specifying observed covariates in stage 2 model

data

data.frame

predictfun

Predictions to be used in stage 2

id1

Optional id-vector of stage 1

id2

Optional id-vector of stage 2

...

Additional arguments to lower level functions

See also

stack.estimate

Examples

m <- lvm(c(y1,y2,y3)~u,c(y3,y4,y5)~v,u~~v,c(u,v)~x) transform(m,u2~u) <- function(x) x^2 transform(m,uv~u+v) <- prod regression(m) <- z~u2+u+v+uv+x set.seed(1) d <- sim(m,1000,p=c("u,u"=1)) ## Stage 1 m1 <- lvm(c(y1[0:s],y2[0:s],y3[0:s])~1*u,c(y3[0:s],y4[0:s],y5[0:s])~1*v,u~b*x,u~~v) latent(m1) <- ~u+v e1 <- estimate(m1,d) pp <- function(mu,var,data,...) { cbind(u=mu[,"u"],u2=mu[,"u"]^2+var["u","u"],v=mu[,"v"],uv=mu[,"u"]*mu[,"v"]+var["u","v"]) } (e <- measurement.error(e1, z~1+x, data=d, predictfun=pp))
#> Estimate Std.Err 2.5% 97.5% P-value #> (Intercept) 0.1358 0.11619 -0.0919 0.3635 2.424e-01 #> x 1.1287 0.11818 0.8971 1.3603 1.290e-21 #> u 0.9437 0.12279 0.7031 1.1844 1.521e-14 #> u2 0.9374 0.09800 0.7454 1.1295 1.115e-21 #> v 1.1385 0.09988 0.9427 1.3342 4.289e-30 #> uv 1.0375 0.10544 0.8309 1.2442 7.559e-23
## uu <- seq(-1,1,length.out=100) ## pp <- estimate(e,function(p,...) p["(Intercept)"]+p["u"]*uu+p["u2"]*uu^2)$coefmat if (interactive()) { plot(e,intercept=TRUE,line=0) f <- function(p) p[1]+p["u"]*u+p["u2"]*u^2 u <- seq(-1,1,length.out=100) plot(e, f, data=data.frame(u), ylim=c(-.5,2.5)) }