Exercise 8.3. The TV dataset is a large sample of TV viewers whose behavior had been recorded for the Neilsen ratings. This data set contains sample television audience data from Neilsen Media Research for the week starting November 6, 1995.

library(vcdExtra)
## Loading required package: vcd
## Loading required package: grid
## Loading required package: gnm
library(reshape)
library(nnet)
library(effects)
## Loading required package: carData
## 
## Attaching package: 'carData'
## The following object is masked from 'package:vcdExtra':
## 
##     Burt
## lattice theme set by effectsTheme()
## See ?effectsTheme for details.
library(ca)

(a) Collapse the TV data to a 5x3 two-way table (ignore the effect of time) whereas the rows are the days of the week and the columns are networks.

Treating Network as a three-level response variable, fit a generalized logit model to explain the variation in viewing in relation to Day and Time. The TV data is a three-way table, so you will need to convert it to a frequency data frame first.

data("TV", package="vcdExtra")
TV.df <- as.data.frame.table(TV)
TV.twoway <- cast(TV.df,fun.aggregate = sum, Day ~ Network)
## Using Freq as value column.  Use the value argument to cast to override this choice
TV.twoway
##         Day  ABC  CBS  NBC
## 1    Monday 2847 2923 2629
## 2   Tuesday 3110 2403 2568
## 3 Wednesday 2434 1283 2212
## 4  Thursday 1766 1335 5886
## 5    Friday 2737 1479 1998

(b) Fit the main-effects model, Network ~ Day + Time, with multinom (). Note that you will have to supply the weights argument because each row of TV.df represents the number of viewers in the Freq variable.

TV.multinom <- multinom(Network ~ Day + Time, data = TV.df, weights = Freq, Hess = TRUE)
## # weights:  48 (30 variable)
## initial  value 41318.808177 
## iter  10 value 38935.947713
## iter  20 value 38818.222728
## iter  30 value 38756.956301
## final  value 38752.186202 
## converged

(c) Prepare an effects plot for the fitted probabilities in this model.

plot(Effect(c("Day", "Time"), TV.multinom), style= "lines", key.args= list(x= 0.05, y= .9))

(d) Interpret these results in comparison to the correspondence analysis in part(a).

TV.ca <- ca(TV.twoway)
plot(TV.ca)

Correspondence analysis for part(a) shows that People watch CBS on Mondays and Tuesdays, ABC on Wednesdays and Fridays, and NBC on Thursdays. Effect plot in part(c) shows a very simila result as for which day in the week people wathch which network.