Open
Description
I tried to adopt an example, where predict()
was used in combination with cbind()
and the newdata
-data frame. But, e.g. looking at rows 1, 7 and 13, you see that these refer to the same combination hincome = 20, children = absent and response = not.work, but all rows have different predicted probabilities.
That raises the question if I use as.data.frame(predict())
, how do I find out which row corresponds to which combination of factor levels and response level?
library(nestedLogit)
data("Womenlf", package = "carData")
m <- nestedLogit(partic ~ hincome + children,
logits(
work = dichotomy("not.work", c("parttime", "fulltime")),
full = dichotomy("parttime", "fulltime")
),
data = Womenlf
)
new <- expand.grid(
hincome = c(20, 30, 40),
children = c("absent", "present")
)
cbind(new, predict(m, newdata = new))
#> hincome children response p se.p logit se.logit
#> 1 20 absent not.work 0.379973389 0.061556512 -0.48966118 0.2612826
#> 2 30 absent parttime 0.129436733 0.047148453 -1.90594822 0.4184172
#> 3 40 absent fulltime 0.490589878 0.066559091 -0.03764493 0.2663307
#> 4 20 present not.work 0.483361927 0.095465380 -0.06657687 0.3822848
#> 5 30 present parttime 0.224958781 0.095638728 -1.23699902 0.5485371
#> 6 40 present fulltime 0.291679292 0.101605781 -0.88724209 0.4917936
#> 7 20 absent not.work 0.588194721 0.133170256 0.35650744 0.5497867
#> 8 30 absent parttime 0.285272275 0.128164048 -0.91845759 0.6285879
#> 9 40 absent fulltime 0.126533004 0.097928271 -1.93196717 0.8860491
#> 10 20 present not.work 0.747625342 0.037830221 1.08598725 0.2004976
#> 11 30 present parttime 0.199129118 0.034884708 -1.39174629 0.2187448
#> 12 40 present fulltime 0.053245540 0.019740560 -2.87812574 0.3915966
#> 13 20 absent not.work 0.818923571 0.052610678 1.50907156 0.3547877
#> 14 30 absent parttime 0.165901061 0.049355986 -1.61496044 0.3566754
#> 15 40 absent fulltime 0.015175368 0.011491854 -4.17278999 0.7689391
#> 16 20 present not.work 0.873487849 0.059489224 1.93215586 0.5383308
#> 17 30 present parttime 0.122673467 0.057838540 -1.96735317 0.5374096
#> 18 40 present fulltime 0.003838684 0.004592451 -5.55877971 1.2009709
Created on 2023-05-31 with reprex v2.0.2
Metadata
Metadata
Assignees
Labels
No labels