Replies: 3 comments 4 replies
-
The problem is likely that you have hard-coded the polynomials in the dataset before fitting your model. Polynomials should be specified in the fitting formula. Please read the section on polynomials: https://marginaleffects.com/chapters/interactions.html#polynomial-regression Also, note that the above is speculation, because you did not supply sufficient information to answer. Please read this page on how to ask good questions about software: |
Beta Was this translation helpful? Give feedback.
-
My apologies for assuming that this is a rather generic question. I've created a self-contained example to demonstrate the issue. I have to admit that the last step of the example is merely an assumption. `library(MASS) # create dataset # outcome: acute kidney injury stages 0 through 3 with 0<1<2<3 my_df<-data.frame(AGE_ord,AKI_ord) # run ordered logistic regression # compute marginal effects I model the stage of acute kidney injury (0 through 3) as a function of the patients' age class (1 through 4). Both outcome and predictor are declared as ordered factors. The proportional odds logistic regression uses the predictor as is, i.e. I do not specify polynomials or anything. The summary of the model contains the estimates:
The output of avg_comparison() is a vector of length 12. It is merely a bold assumption of mine that these are four estimates, one per outcome level, for each of the three estimates AGE_ord.L through AGE_ord.C. This is why I converted it to a matrix with the labels showing my assumption:
I'll rephrase my questions somewhat more cautiously: How do I compute the total marginal effect of a plus-one unit change of AGE_ord? |
Beta Was this translation helpful? Give feedback.
-
I recommend you forget about this whole idea of polynomial, stop reshaping the data, and try to interpret the results directly as printed by I also think it might be beneficial for you to read I have published online for free. Especially chapter 9 on categorical outcomes, and chapters 3, 4, 5, 6 on the conceptual framework: https://marginaleffects.com/ Scroll all the way down for two sentences of interpretation. library(MASS)
library(marginaleffects)
set.seed(48103)
AGE_ord <- sample(1:4, 100, replace = TRUE)
AGE_ord <- factor(AGE_ord, ordered = TRUE)
CCTIME_num <- sample(30:90, 100, replace = TRUE)
DM_yn <- sample(0:1, 100, replace = TRUE)
DM_yn <- factor(DM_yn)
AKI_ord <- sample(0:3, 100, replace = TRUE)
AKI_ord <- factor(AKI_ord, ordered = TRUE)
my_df <- data.frame(AGE_ord, CCTIME_num, DM_yn, AKI_ord)
olmod <- polr(AKI_ord ~ AGE_ord + CCTIME_num + DM_yn, data = my_df, Hess = TRUE)
cmp <- avg_comparisons(olmod, variables = list("AGE_ord" = "sequential"))
cmp
#>
#> Group Contrast Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
#> 0 2 - 1 0.13036 0.0950 1.372 0.170 2.6 -0.0558 0.3166
#> 0 3 - 2 -0.05162 0.1018 -0.507 0.612 0.7 -0.2511 0.1479
#> 0 4 - 3 0.04175 0.1089 0.383 0.701 0.5 -0.1717 0.2552
#> 1 2 - 1 0.03777 0.0326 1.160 0.246 2.0 -0.0261 0.1016
#> 1 3 - 2 -0.00918 0.0192 -0.478 0.633 0.7 -0.0468 0.0285
#> 1 4 - 3 0.00793 0.0207 0.383 0.701 0.5 -0.0326 0.0485
#> 2 2 - 1 -0.05819 0.0446 -1.305 0.192 2.4 -0.1456 0.0292
#> 2 3 - 2 0.02638 0.0521 0.506 0.613 0.7 -0.0758 0.1285
#> 2 4 - 3 -0.02119 0.0558 -0.380 0.704 0.5 -0.1306 0.0882
#> 3 2 - 1 -0.10994 0.0845 -1.302 0.193 2.4 -0.2755 0.0556
#> 3 3 - 2 0.03443 0.0684 0.503 0.615 0.7 -0.0997 0.1685
#> 3 4 - 3 -0.02850 0.0735 -0.388 0.698 0.5 -0.1725 0.1155
#>
#> Term: AGE_ord
#> Type: probs First row of output: On average, moving from Last row of output: On average, moving from |
Beta Was this translation helpful? Give feedback.
-
I compute an ordinal logistic regression model with MASS::polr(). One of the predictors is an ordinal parameter AGE with four levels. I understand that the polr-generated model contains three estimates (one less than the number of levels), with AGE.L, AGE.Q, and AGE.C denoting linear, quadratic, and cubic terms, respectively. Now I use avg_comparison() to compute the marginal effects of a +1 unit change, which again returns linear, quadratic, and cubic terms of AGE.
Now I want to quantify the total marginal effect MEt of AGE. Is the math as simple as this:
MEt=ME.L+(ME.Q*u)+(ME.C*u^2), which equals ME.L+ME.Q+ME.C for u=1?
Thanks
Markus
Beta Was this translation helpful? Give feedback.
All reactions