# Swiss Labour Market
library(AER)
data("SwissLabor")
# recode factors
sl <- SwissLabor
sl$participation <- as.numeric(sl$participation)-1
sl$foreign <- as.numeric(sl$foreign)-1
if (FALSE) {
fit1 <- TSVC(participation~income+age, data=sl, family=binomial(link="logit"),
nperm=300, trace=TRUE)
print(fit1)
class(fit$model) # glm
# In fit2, variable 'foreign' does not serve as effect modifier
# and the effect of 'foreign' is not modified by the other variables.
# That means 'foreign' is assumed to only have simple linear effect on the response.
fit2 <- TSVC(participation~income+age+foreign, data=sl, family=binomial(link="logit"),
nperm=300, trace=TRUE, effmod=c("income","age"),
notmod=list(c("foreign","income"),c("foreign","age")))
print(fit2)
# In fit3, variable 'age' does only serve as effect modifier. That means the effect of 'age'
# is not included in the predictor of the model.
fit3 <- TSVC(participation~income+age+foreign, data=sl, family=binomial(link="logit"),
nperm=300, trace=TRUE, only_effmod="age")
print(fit3)
# In fit4, the intercept is allowed to be modified by 'age' and 'income'.
# The two covariates, however, are not allowed to modify each other.
fit4 <- TSVC(participation~income+age, data=sl, family=binomial(link="logit"),
nperm=300, trace=TRUE, split_intercept=TRUE,
notmod=list(c("income","age"), c("age", "income")))
print(fit4)
# In fit5, variable 'age' has a smooth effect on the response.
# Hence, the (smooth) effect of 'age' will not be modified by the other variables.
fit5 <- TSVC(participation~income+age+foreign, data=sl, family=binomial(link="logit"),
nperm=300, trace=TRUE, smooth="age")
print(fit5)
class(fit5$model) # gam
# In fit6, the intercept is allowed to be modified by 'age' and 'income', but the two variables are
# not included in the predictor of the model. Here, no permutation tests are performed, but the
# tree is pruned by a minimum node size constraint.
fit6 <- TSVC(participation~income+age, data=sl, family=binomial(link="logit"),
perm_test=FALSE, nodesize_min=100, bucket_min=100, trace=TRUE, split_intercept=TRUE,
effmod=c("income","age"), only_effmod = c("income", "age"))
print(fit6)
}
Run the code above in your browser using DataLab