## example 1:
# the data consist of ages (in months) at which an
# infant starts to walk alone.
# prepare data
DATA1 <- subset(ZelazoKolb1972, Group != "Control")
# fit unrestricted linear model
fit1.lm <- lm(Age ~ -1 + Group, data = DATA1)
# the variable names can be used to impose constraints on
# the corresponding regression parameters.
coef(fit1.lm)
# constraint syntax: assuming that the walking
# exercises would not have a negative effect of increasing the
# mean age at which a child starts to walk.
myConstraints1 <- ' GroupActive < GroupPassive < GroupNo '
iht(fit1.lm, myConstraints1)
# another way is to first fit the restricted model
fit.restr1 <- restriktor(fit1.lm, constraints = myConstraints1)
iht(fit.restr1)
# Or in matrix notation.
Amat1 <- rbind(c(-1, 0, 1),
c( 0, 1, -1))
myRhs1 <- rep(0L, nrow(Amat1))
myNeq1 <- 0
fit1.con <- restriktor(fit1.lm, constraints = Amat1,
rhs = myRhs1, neq = myNeq1)
iht(fit1.con)
Run the code above in your browser using DataLab