It looks to me like the code is using the test sample mean to calculate null deviance, but the associated text says: The resulting R^2 values are especially striking: the full model has a negative R^2, indicating that its predictions are further from new observations than you get using the training sample mean as your predictor.
It looks to me like the code is using the test sample mean to calculate null deviance, but the associated text says: The resulting R^2 values are especially striking: the full model has a negative R^2, indicating that its predictions are further from new observations than you get using the training sample mean as your predictor.