# let's prepare some data
data(employment2)
data(unemployed)
table_data <- employment2[employment2$Contract == "FT", ]
y <- unemployed[unemployed$age == "20_24" & unemployed$year == 2015,]
countries <- intersect(levels(droplevels(y$country)), levels(table_data$Country))
table_data <- table_data[table_data$Country %in% countries, ]
y <- y[y$country %in% countries, c("country", "value")]
colnames(y) <- c("Country", "unemployed")
# response as part of X
table_data.y <- merge(table_data, y, by = "Country")
reg.cla <- bpcRegTab(table_data.y, y = "unemployed", obs.ID = "Country",
row.factor = "Sex", col.factor = "Age", value = "Value")
reg.cla
# response as named array
resp <- y$unemployed
names(resp) <- y$Country
reg.cla2 <- bpcRegTab(table_data.y, y = resp, obs.ID = "Country",
row.factor = "Sex", col.factor = "Age", value = "Value")
reg.cla2
# response as data.frame, robust estimator, 55plus as the rationing category, logarithm of base 2
resp.df <- as.data.frame(y$unemployed)
rownames(resp.df) <- y$Country
reg.rob <- bpcRegTab(table_data.y, y = resp.df, obs.ID = "Country",
row.factor = "Sex", col.factor = "Age", value = "Value",
norm.cat.col = "55plus", robust = TRUE, base = 2)
reg.rob
# Illustrative example with non-compositional predictors and response as part of X
x.ext <- unemployed[unemployed$age == "15_19" & unemployed$year == 2015,]
x.ext <- x.ext[x.ext$country %in% countries, c("country", "value")]
colnames(x.ext) <- c("Country", "15_19")
table_data.y.ext <- merge(table_data.y, x.ext, by = "Country")
reg.cla.ext <- bpcRegTab(table_data.y.ext, y = "unemployed", obs.ID = "Country",
row.factor = "Sex", col.factor = "Age", value = "Value", external = "15_19")
reg.cla.ext
Run the code above in your browser using DataLab