[R] Using weights with truncreg
Achim Zeileis
Achim.Zeileis at uibk.ac.at
Mon Jun 13 21:35:21 CEST 2016
On Mon, 13 Jun 2016, Ganz, Carl wrote:
> Hello everyone,
>
> I would like to use truncreg on survey data with weights, but so far as I can tell the weight parameter in truncreg is not working. I find that using weights does not actually change the output.
>
> Here is a small reproducible example using the example in the documentation:
>
> ## simulate a data.frame
> set.seed(1071)
> n <- 10000
> sigma <- 4
> alpha <- 2
> beta <- 1
> x <- rnorm(n, mean = 0, sd = 2)
> eps <- rnorm(n, sd = sigma)
> y <- alpha + beta * x + eps
> d <- data.frame(y = y, x = x)
>
> ## truncated response
> d$yt <- ifelse(d$y > 1, d$y, NA)
>
> ## binary threshold response
> d$yb <- factor(d$y > 0)
>
> ## censored response
> d$yc <- pmax(1, d$y)
>
> ## random weight
> wgt <- runif(10000,500,1500)
> ## unweighted
> fm_trunc <- truncreg(yt ~ x, data = d, point = 1, direction = "left")
> ## weighted
> fm_trunc_weighted <- truncreg(yt ~ x, data = d, weights = wgt, point = 1, direction = "left")
>
> coef(fm_trunc_weighted)==coef(fm_trunc) # all equal
>
> Am I misunderstanding how the weight parameter works for truncreg or is
> the weight parameter not working?
I think you are right and the 'weights' argument in truncreg() is
currently not used.
As an alternative you can use the "crch" package for censored (and
truncated) regression with conditional heteroskedasticity. The models
above can be fitted via:
library("crch")
fm_trunc2 <- trch(yt ~ x, data = d, left = 1)
fm_trunc_weighted2 <- trch(yt ~ x, data = d, weights = wgt, left = 1)
Note that by default a log-link is used for the sigma/scale parameter to
assure positivity. But you can also set link.scale="identity" to obtain
the same results as in truncreg().
> Kind Regards,
> Carl
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list