

housing(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 variables.

_A_r_g_u_m_e_n_t_s_:

     Sat: Satisfaction of householders with their present
          housing circumstances, (High, Medium or Low).

    Infl: Percieved degree of influence householders have on
          the management of the property (High, Medium,
          Low).

    Type: Type of rental accommodation, (Tower, Atrium,
          Apartment, Terrace).

    Cont: Contact residents are afforded with other resi-
          dents, (Low, High).

    Freq: Frequencies: the numbers of residents in each
          class.

_F_o_r_m_a_t_:

_S_o_u_r_c_e_:

     Madsen, M. (1976) Statistical analysis of multiple con-
     tingency tables. Two examples.  Scand. J. Statist., 3,
     97-106.

     Cox, D. R. and Snell, E. J. (1984) Applied Statistics,
     Principles and Examples, Chapman  Hall.

_E_x_a_m_p_l_e_s_:

     data(housing)
     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.resid)

     dropterm(house.glm1, test="Chisq")

     addterm(house.glm1, ~. + Sat:(Infl+Type+Cont)^2, test = "Chisq")

     hnames <- lapply(housing[, -5], levels) # omit Freq
     house.pm <- predict(house.glm1, expand.grid(hnames),
                        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.mult
     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, ])
     sort(drop(house.ld))
     mean(.Last.value)

     house.plr <- polr(Sat ~ Infl + Type + Cont,
                    data = housing, weights = Freq)
     house.plr

     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

