 Ajustit-prediction plots are commonly used to visualize interactions and non-literal models. Status user manual refers to these as marginal prediction plots, but there is nothing marginal about the plots and therefore the term adjusted prediction plots is a bit more preferable. So what exactly is adjusted when we do these plots? Normally when you plot an interaction model the first thing that you learn is to use one of these Excel files. So this is from Jeremy Dawson's website and this is one of the better Excel sheets and one of the better sources for these sheets because he has multiple different sheets for different purposes. How these sheets work is that you plug in the recursion coefficients for the independent variable, this one allows you to have quadratic terms and then you plug in the values for the moderator and the intercept. So you can have a non-linear effect, a u-shape or parabola of one variable and then one moderator, but so basically two variables that explain the dependent variable. What if you have more than two predictors in the model? So what if our model looks like that? So we have these x2, x3 and x4, how do you take those into account? Because the values of this axis determine the value of the dependent variable and that needs to be taken into account when you do the plotting. So in practice what you do here is that you simply set all the x's at their means and you calculate the weighted sum of the means and then you add the intercept and that goes into the intercept here. So all other covariates are held at their mean values when you apply these exhaust sheets to visualize recursion models. There are a couple of issues in these at means predictions. The first issue is that prediction at mean is not mean of predictions in non-linear models. So if you want to predict for example, what is the average value for men and average value for women and then you want to take average of those, if the model is non-linear, you need to actually calculate the average male prediction, average female prediction and then calculate the mean instead of trying to estimate a predict value that is for a person who is half man and half woman. Which brings us to the second issue, which is that some of these predictions that you would calculate using these excel sheets don't really make sense. So there is no such person that is half man and half woman. We are interested in effects for men and women and sometimes average effect over men and women, but not on effects for a person who is a half man and half woman. That just doesn't exist. In linear models there are prediction at means is the same as mean of predictions, but in non-linear models this is not the case. So let's take a look at how statistical software calculates adjusted predictions and this is using data. First let's just do simply predictions. So we have this logistic regression model here and we are doing two sets of predictions. We are doing the default predictions that Marching's does, which is the adjusted predictions and then we are doing predictions at means. So what is the difference and why do we get such different values? So this is 0.17, this is 0.12, which is a rather large difference. The first here basically estimates predictions for every case at the values that the case happens to have with x variables and then calculates mean of those predictions. The second one simply calculates means of all x variables and then calculates one predictions using those means of the axis. And we can see clearly that the result is different and this is the kind of prediction that we normally want to have, not this one. To show how these predictions are actually calculated, let's do this calculation manually without the use of margins and the state of commands for that is here. So we simply calculate or predict the fitted value for each case and then we calculate the mean of those cases and we can see that the means are the same. So this is the mean of the predicted values and this is the average marginal prediction as data calls it or average adjusted prediction, which is perhaps the better term. They are the same and now the question is what exactly is adjusted when we do adjusted predictions and why are these called adjusted predictions? Let's take a look at this scenario where we have predictions based on sex. The idea here is that the male prediction here using margins is the average prediction under the scenario that all of these observations were made. So this is how you calculate it. We replace everything, all sex with zeros, that is the male, one is female and then we predict, we take the mean of the predictions and that is our margin here in status output. So basically we are adjusting all the observations. The idea is that we adjust all the observations first to be men. We calculate predictions, we calculate average prediction, we store that value, then we adjust sex again to one so that everyone is female and then we calculate predictions, we calculate the mean of the predictions and that's our margin here in status. So we are predicting based on data that we adjust to specific values that we give in the margins command. Of course the same thing can be done with any statistical software. So what is the advantage of using statistical software compared to using the Excel files? The Excel files are in a way easy to apply because you don't need to understand much about your statistical software to do that and also some statistical software that are not so good such as SPSS don't provide you tools for calculating these plots. So there is that is the advantage of Excel. But then again these Excel things are fairly limited in features, they allow you to plot one or two things. Confidence intervals typically you can't do, you can't visualize the data behind the plots and so on. And they use unrealistic prediction scenarios for non-linear models. For example trying to predict values for a scenario where we have a person who is half man and half woman. And they are also quite error prone so there's copy paste involved and particularly it is possible to plug in the standardized rigorous and coefficients which will completely mess up the plots for reasons that are beyond this video. If you do things with your statistical software it is a lot harder to really mess the plots up. These are also easier to apply so if you know how status margins command or R's margin command or R's prediction command works you can just use that command after regression analysis. It is a lot faster and a lot easier than opening the Excel file and copy pasting or typing the coefficient values in that file particularly if you're doing multiple different models. They are much more flexible in calculating predictions. So you can for example calculate predictions for subgroups. You can have different ranges of the covariates for different subgroups that for example you wouldn't extrapolate beyond the data too much and then you can get confidence interest by default. You can add visualizations to actually show that your data correspond or the lines that you draw correspond your data and they explain your data. Well we talk about that in this working paper and this is less error prone because it's automated. It eliminates some of the human errors from the process. So this is strictly superior approach to the Excel files and that is the one that I use exclusively.