As continuation of this question
I have a model with a continuous predictor and factors. I want the fit of the the model (especially the beta to the continuous predictor) to fit best when 2 factors are "on". I tried to use weights. The results in the toy-example are alright but I can not improve my real world problem.
The example is:
library(AER)
N = 10
f = rep(c("s1","s2","s3","s4","s5","s6","s7","s8"),N)
fcoeff = rep(c(-1,-2,-3,-4,-3,-5,-10,-5),N)
set.seed(100)
x = rnorm(8*N)+1
beta = 5
epsilon = rnorm(8*N,sd = sqrt(1/5))
y.star = x*beta+fcoeff+epsilon ## latent response
y = y.star
y[y<0] <- 0 ## censored response
my.weights = rep(c(1,1,1,2,2,1,1,1),N)
fit <- tobit(y~0+x+f, weights = my.weights)
summary(fit)
coef(fit)
Giving more weight (2 instead of 1) at $s4$ and $s5$ I try to force the model to fit these data points more exactly as errors here are worse than errors elsewhere.
Is this a valid approach? Can this be done differently?
EDIT after Achim Zeileis' answer: I tried to add the interaction with $s4$ and $s5$ using 2 sets of factors:
f = rep(c("s1","s2","s3","s4","s5","s6","s7","s8"),N)
f2 = rep(c("s1","s2","s3","s4","s5","s6","s7","s8"),N)
f[f %in% c("s4","s5")] <- "no.inter"
f2[f2 %in% c("s1","s2","s3","s6","s7","s8")] <- "rest"
fit <- tobit(y~0+x+x*f2+f)
The results is
coef(fit)
x f2rest f2s4 f2s5 fs1 fs2 fs3 fs6 fs7 fs8 x:f2s4 x:f2s5
4.9662343 -4.4759248 -3.7568885 -4.4251267 3.4118712 2.4866271 1.2519721 -0.5528713 -5.4638955 0.0000000 -0.2309364 1.5865312
Thus I get the correct overall beta of 5. A level shift of approx -4.5
and shifts of $s_i,i \in \{1,2,3,6,7,8\}$ that look good with the last one being $0$ thus approximatively giving the shift of $-5$ in connection with the factor f2rest
. Finally there are the interactions with s4
and s5
.
This looks like the solution.
I try to model interaction at those special factors only. I have not seen anyone doing this before. Is it correct that I need to define those 2 sets of factors?
EDIT: I have mixed something up. The above model is singular. I am confused. I don't know how I made the first fit work.