houseprices               package:DAAG               R Documentation

_A_r_a_n_d_a _H_o_u_s_e _P_r_i_c_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     The 'houseprices' data frame consists of the floor area, price,
     and the number of bedrooms for a sample of houses sold in Aranda
     in 1999.  Aranda is a suburb of Canberra, Australia.

_U_s_a_g_e:

     houseprices

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

     This data frame contains the following columns:

     _a_r_e_a a numeric vector giving the floor area

     _b_e_d_r_o_o_m_s a numeric vector giving the number of bedrooms

     _s_a_l_e._p_r_i_c_e a numeric vector giving the sale price in thousands of
          Australian dollars

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

     J.H. Maindonald

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

     plot(sale.price~area, data=houseprices)
     pause()

     coplot(sale.price~area|bedrooms, data=houseprices)
     pause()

     print("Cross-Validation - Example 5.5.2")

     houseprices.lm <- lm(sale.price ~ area, data=houseprices)
     summary(houseprices.lm)$sigma^2
     pause()

     cv.lm()
     pause()

     print("Bootstrapping - Example 5.5.3")
     houseprices.fn <- function (houseprices, index){
     house.resample <- houseprices[index,]
     house.lm <- lm(sale.price ~ area, data=house.resample)
     coef(house.lm)[2]    # slope estimate for resampled data
     }
     require(boot)       # ensure that the boot package is loaded
     houseprices.boot <- boot(houseprices, R=999, statistic=houseprices.fn)

     houseprices1.fn <- function (houseprices, index){
     house.resample <- houseprices[index,]
     house.lm <- lm(sale.price ~ area, data=house.resample)
     predict(house.lm, newdata=data.frame(area=1200))
     }

     houseprices1.boot <- boot(houseprices, R=999, statistic=houseprices1.fn)
     boot.ci(houseprices1.boot, type="perc") # "basic" is an alternative to "perc"
     houseprices2.fn <- function (houseprices, index){
     house.resample <- houseprices[index,]
     house.lm <- lm(sale.price ~ area, data=house.resample)
     houseprices$sale.price-predict(house.lm, houseprices)  # resampled prediction errors
     }

     n <- length(houseprices$area)
     R <- 200   
     houseprices2.boot <- boot(houseprices, R=R, statistic=houseprices2.fn)
     house.fac <- factor(rep(1:n, rep(R, n)))
     plot(house.fac, as.vector(houseprices2.boot$t), ylab="Prediction Errors", 
     xlab="House")
     pause()

     plot(apply(houseprices2.boot$t,2, sd)/predict.lm(houseprices.lm, se.fit=TRUE)$se.fit,
          ylab="Ratio of Bootstrap SE's to Model-Based SE's", xlab="House", pch=16)
     abline(1,0)

