# NOT RUN {
#####################
### Simple example for basic effectstars function
p <- 4; k <- 5
coefs <- matrix(exp(rnorm(p*k,sd=0.5)),ncol=k)
rownames(coefs) <- paste("Variable",1:p)
colnames(coefs) <- paste("Cat",1:k)
effectstars(coefs)
#####################
### Example for effect stars for a multivariate logit model
data(xs.nz, package = "VGAMdata")
xs.nz$age <- scale(xs.nz$age)
library(VGAM)
cats_dogs <- vglm(cbind(cat, dog) ~ age + sex + marital,
data = xs.nz, family = binom2.or(zero = NULL))
summary(cats_dogs)
## quick and dirty
effectstars(exp(coef(cats_dogs, matrix = TRUE)))
## make it pretty
# create the effects matrix you want to plot, name rows and columns
effects <- exp(coef(cats_dogs, matrix = TRUE))
colnames(effects) <- c("cat", "dog", "OR")
rownames(effects) <- c("Intercept", "Age", "Gender", rep("Marital", 3))
# create subtitles containing category labels of predictors
subs <- c(rep("",2), "(male)", "(married)", "(separated/divorced)", "(widowed)")
# create labels containing the response categories and all p-values
p_values <- formatC(summary(cats_dogs)@coef3[,4], format="f", digits=3)
labels <- matrix(paste0(rep(c("cat", "dog", "OR"), nrow(effects)), "\n(", p_values, ")"),
byrow = TRUE, ncol = 3)
# plot effectstars
effectstars(effects, labels = labels, subs = subs)
#####################
## Example for method effectstars.vglm for a multinomial logit model calculated in VGAM
data(election)
library(VGAM)
m_elect <- vglm(Partychoice ~ Gender + West + Age + Union + Highschool + Unemployment
+ Pol.Interest + Democracy + Religion, family = multinomial(), data = election)
effectstars(m_elect)
# }
Run the code above in your browser using DataLab