housing package:MASS R Documentation _F_r_e_q_u_e_n_c_y _T_a_b_l_e _f_r_o_m _a _C_o_p_e_n_h_a_g_e_n _H_o_u_s_i_n_g _C_o_n_d_i_t_i_o_n_s _S_u_r_v_e_y _D_e_s_c_r_i_p_t_i_o_n: The 'housing' data frame has 72 rows and 5 variables. _U_s_a_g_e: housing _F_o_r_m_a_t: '_S_a_t' Satisfaction of householders with their present housing circumstances, (High, Medium or Low, ordered factor). '_I_n_f_l' Perceived degree of influence householders have on the management of the property (High, Medium, Low). '_T_y_p_e' Type of rental accommodation, (Tower, Atrium, Apartment, Terrace). '_C_o_n_t' Contact residents are afforded with other residents, (Low, High). '_F_r_e_q' Frequencies: the numbers of residents in each class. _S_o_u_r_c_e: Madsen, M. (1976) Statistical analysis of multiple contingency tables. Two examples. _Scand. J. Statist._ *3*, 97-106. Cox, D. R. and Snell, E. J. (1984) _Applied Statistics, Principles and Examples_. Chapman & Hall. _R_e_f_e_r_e_n_c_e_s: Venables, W. N. and Ripley, B. D. (2002) _Modern Applied Statistics with S._ Fourth edition. Springer. _E_x_a_m_p_l_e_s: options(contrasts = c("contr.treatment", "contr.poly")) # Surrogate Poisson models house.glm0 <- glm(Freq ~ Infl*Type*Cont + Sat, family = poisson, data = housing) summary(house.glm0, cor = FALSE) addterm(house.glm0, ~. + Sat:(Infl+Type+Cont), test = "Chisq") house.glm1 <- update(house.glm0, . ~ . + Sat*(Infl+Type+Cont)) summary(house.glm1, cor = FALSE) 1 - pchisq(deviance(house.glm1), house.glm1$df.residual) dropterm(house.glm1, test = "Chisq") addterm(house.glm1, ~. + Sat:(Infl+Type+Cont)^2, test = "Chisq") hnames <- lapply(housing[, -5], levels) # omit Freq newData <- expand.grid(hnames) newData$Sat <- ordered(newData$Sat) house.pm <- predict(house.glm1, newData, type = "response") # poisson means house.pm <- matrix(house.pm, ncol = 3, byrow = TRUE, dimnames = list(NULL, hnames[[1]])) house.pr <- house.pm/drop(house.pm %*% rep(1, 3)) cbind(expand.grid(hnames[-1]), round(house.pr, 2)) # Iterative proportional scaling loglm(Freq ~ Infl*Type*Cont + Sat*(Infl+Type+Cont), data = housing) # multinomial model library(nnet) (house.mult<- multinom(Sat ~ Infl + Type + Cont, weights = Freq, data = housing)) house.mult2 <- multinom(Sat ~ Infl*Type*Cont, weights = Freq, data = housing) anova(house.mult, house.mult2) house.pm <- predict(house.mult, expand.grid(hnames[-1]), type = "probs") cbind(expand.grid(hnames[-1]), round(house.pm, 2)) # proportional odds model house.cpr <- apply(house.pr, 1, cumsum) logit <- function(x) log(x/(1-x)) house.ld <- logit(house.cpr[2, ]) - logit(house.cpr[1, ]) (ratio <- sort(drop(house.ld))) mean(ratio) (house.plr <- polr(Sat ~ Infl + Type + Cont, data = housing, weights = Freq)) house.pr1 <- predict(house.plr, expand.grid(hnames[-1]), type = "probs") cbind(expand.grid(hnames[-1]), round(house.pr1, 2)) Fr <- matrix(housing$Freq, ncol = 3, byrow = TRUE) 2*sum(Fr*log(house.pr/house.pr1)) house.plr2 <- stepAIC(house.plr, ~.^2) house.plr2$anova