Dependent (Response) Variable Extracted
depvar.RdA generic function that extracts the response/dependent variable from objects.
Arguments
- object
An object that has some response/dependent variable.
- ...
-
Other arguments fed into the specific methods function of the model. The following mainly applies to
"vglm"classobjects. In particular, sometimestype = c("lm", "lm2")is available, in which case the first one is chosen if the user does not input a value. The latter value corresponds to argumentform2, and sometimes a response for that is optional.Another argument is
muxypw(whose default isFALSE) which is whetherobject@yneeds to be multiplied by the prior weight. This feature is useful for family functions that store sample proportions inobject@yand the prior weights inobject@prior.weightsbecause sometimes the count response is needed, e.g., forvglmnet(). So if onobject@family@infos()muxypw == FALSEand ifMux4vglmnet = TRUEthen setdepvar(object, muxypw = TRUE)to get the raw counts. Also, becauseroundmux = FALSEis the default, it is a good idea to setroundmux = TRUEto make sure the result is integer-valued, i.e.,depvar(object, muxypw = TRUE, roundmux = TRUE). Note that recycling is used.
Examples
pneumo <- transform(pneumo, let = log(exposure.time))
(fit <- vglm(cbind(normal, mild, severe) ~ let, propodds, pneumo))
#>
#> Call:
#> vglm(formula = cbind(normal, mild, severe) ~ let, family = propodds,
#> data = pneumo)
#>
#>
#> Coefficients:
#> (Intercept):1 (Intercept):2 let
#> -9.676093 -10.581725 2.596807
#>
#> Degrees of Freedom: 16 Total; 13 Residual
#> Residual deviance: 5.026826
#> Log-likelihood: -25.09026
fit@y # Sample proportions (not recommended)
#> normal mild severe
#> 1 1.0000000 0.00000000 0.00000000
#> 2 0.9444444 0.03703704 0.01851852
#> 3 0.7906977 0.13953488 0.06976744
#> 4 0.7291667 0.10416667 0.16666667
#> 5 0.6274510 0.19607843 0.17647059
#> 6 0.6052632 0.18421053 0.21052632
#> 7 0.4285714 0.21428571 0.35714286
#> 8 0.3636364 0.18181818 0.45454545
depvar(fit) # Better than using fit@y
#> normal mild severe
#> 1 1.0000000 0.00000000 0.00000000
#> 2 0.9444444 0.03703704 0.01851852
#> 3 0.7906977 0.13953488 0.06976744
#> 4 0.7291667 0.10416667 0.16666667
#> 5 0.6274510 0.19607843 0.17647059
#> 6 0.6052632 0.18421053 0.21052632
#> 7 0.4285714 0.21428571 0.35714286
#> 8 0.3636364 0.18181818 0.45454545
weights(fit, type = "prior") # Number of observations
#> [,1]
#> 1 98
#> 2 54
#> 3 43
#> 4 48
#> 5 51
#> 6 38
#> 7 28
#> 8 11
# This is new:
fit@family@infos()$muxypw # Proportion or count?
#> [1] FALSE
fit@family@infos()$Mux4vglmnet # vglmnet needs counts?
#> [1] TRUE
fit@family@infos()$roundmux # Product is integer-valued?
#> [1] TRUE
depvar(fit, muxypw = TRUE, roundmux = TRUE) # Counts
#> normal mild severe
#> 1 98 0 0
#> 2 51 2 1
#> 3 34 6 3
#> 4 35 5 8
#> 5 32 10 9
#> 6 23 7 8
#> 7 12 6 10
#> 8 4 2 5