## Regression for car segment shares
## ---------------------------------
data(carseg)
## Extract the compositions
uc <- as.matrix(carseg[,(1:5)])
## Extract the explanatory variables
attach(carseg)
## Example 1: without formula
## --------------------------
## Change some variables
dc <- data.frame(l.exp1=log(expend)*PAC,l.exp0=log(expend)*(1-PAC), l.sent=log(sent),
l.FBCF=log(FBCF), l.price=log(price), rates)
## Define the log-ratio transformation matrix
Vc <- matrix(c( 1,0,0,0,
-1,1,0,0,
0,-1,1,0,
0,0,-1,1,
0,0,0,-1),ncol=4,byrow=TRUE)
colnames(Vc) <- c("AB","BC","CD","DE")
rownames(Vc) <- colnames(uc)
Vc
# 2 next rows only necessary when calling regSGB without a formula.
dc1 <- cbind("(Intercept)"= 1 , dc)
dc1 <- as.matrix(dc1)
object10 <- regSGB(dc1,uc, Vc,shape10=4.4)
summary(object10)
## Example 2: same with formula
## ----------------------------
## Define the formula
Form <- Formula(AB | BC | CD | DE ~ l.exp1 + l.exp0 + l.sent + l.FBCF + l.price + rates)
## Regression with formula
object1 <- regSGB(Form, data= list(dc, uc, Vc),shape10=4.4)
summary(object1)
## Example 3: Usage of I()
## -----------------------
Form2 <- Formula(AB | BC | CD | DE ~ I(l.exp1 + l.exp0) + l.exp1 +l.sent +
l.FBCF + l.price + rates )
object2 <- regSGB(Form2,data= list(dc, uc, Vc),shape10=4.4)
object2
## Example 4: Usage of variable transformations on the original file
## -----------------------------------------------------------------
Form3 <- Formula(AB | BC | CD | DE ~ log(expend) + I(PAC*log(expend)) + log(sent) + log(FBCF) +
log(price) + rates)
object3 <- regSGB(Form3, data=list(carseg, uc, Vc),shape10=4.4)
object3
object2[["par"]]-object3[["par"]] # same results
## Example 5: Fixing parameter values
## ----------------------------------
## 1. In the following regression we condition on shape1 = 2.36.
object4 <- regSGB(Form3,data=list(carseg, uc, Vc),
shape10 = 4.4, bound = 2.0, ind = 1, shape1 = 2.36)
summary(object4)
## 2. In the following regression we condition on shape1 = 2.36 and the coefficient of
## log(FBCF).BC = 0. Notice that it is the 19th parameter.
object5 <- regSGB(Form3,data=list(carseg, uc, Vc),
shape10 = 4.4, bound = 2.0, ind = c(1,19) , shape1 = 2.36)
summary(object5)
object3[["AIC"]]
object4[["AIC"]] # largest AIC
object5[["AIC"]]
Run the code above in your browser using DataLab