 Svečen, je Oliver Perra, in to je pravda pravda na vsebe. Na pravda pravda, sem vsebe vsebe, in na pravda pravda sem vsebe, vsebe vsebe vsebe. Na pravda pravda, sem vsebe, kako je pravda vsebe. And the Bayesian approaches uses algorithms to estimate the posterior distribution of the parameter value combinations of interest. So in the linear model we had different parameters and we need to use some algorithms to estimate the plausibility of these different parameters. Combinations depend conditionally on the data collected and conditionally on the model assumptions the priors had specified. And the best algorithms for this task are Markov chain Monte Carlo algorithms. This can represent the probability distribution of a combination of parameters by taking a series of random walks across the parameter space using a set of rules. And these set of rules basically ensure that these random walks will be more often in the direction of high probability regions. This also ensures that at the end of these walks, which are called chains, the algorithm should have done a fair bit of exploration that ensures it can provide a reliable high definition description of the underlying posterior distribution. So this was a very non-technical description of the algorithms and the Markov chain walks, but you can find more details in the references I have attached with this module. The problem with these algorithms is that they can get stuck in some unrepresentative regions of the parameter space. So an important issue to check is that the algorithm converged. Another problem is that the solutions of the algorithm may not be stable, so the algorithms may provide solutions that are not well defined. Now, a version of the Markov chain approach that has proved to be very efficient and reliable is the Hamiltonian Monte Carlo. And this is implemented in R through STAN, and is particularly approachable using the rethinking package created by McElrah. And again, I refer to the book statistical rethinking that provides a lot of details about these methods. An advantage of the Hamiltonian Monte Carlo approach lies in the fact that it will provide error messages when some key problems arise. So here on the left side of the slide, you can see the model I had developed in the second presentation. So this is a linear regression model of new weight, so the variable bw here. And newborn's birth weight is supposed to be normally distributed around average mu and with a standard deviation sigma. So this is the likelihood function. The linear model specified in the second line says basically that the average birth weight of newborns is supposed to be a linear function of an intercept and the slope that represents the rate of change in newborn's birth weight associated with deviations of maternal weight from the general weight. And then I have some prior assumptions about the intercept A, the slope B, and the standard deviation sigma. So the intercept A is supposed to be normally distributed around an average of 3,300 grams. The slope B is supposed to be normally distributed around the average of zero, so I emphasized in the second presentation that this is a skeptical assumption. So I am not taking sides in a way I am giving equal probability to the slope B negative positive or null, so with no association between predictor and outcome. And finally, the assumptions for the standard deviation is that any value between zero and one kilo are equally likely. Beside this, on the right side of the panel, you can see how to write this model using the rethinking package. The rethinking package is basically specifying an M1 model. I call this model M1, but you can call it with any other name you want. And the option ULAM is basically using or invoking a Hamiltonian Monte Carlo approach to estimate this model. So the other options after a list are basically specifying the model likelihood of the model first. So variable BW birth weight is supposed to be approximately normally distributed with mean mu and standard deviation sigma. Then I have the linear model where mu is a function of A of the sum of A and the sum of the product of B by the maternal weight. And then I have priors for A, B and sigma. And finally, you can see that the other options in the right side panel asked the program to use four chains, sorry, six chains. And it is actually recommended to use more than four, or at least four chains usually to have reliable solutions. And these chains are now distributed across different core processes of the machine. And you can follow the script and the analysis using the script I have provided with the material of this module. So you can see how to run these analysis. To avoid problems in estimation or issues in the length of time for the estimation. It is also advisable to specify datasets or lists of data. We've only the variables of interest when you're using ULAM option thinking. And here you can see the output I have seen running these analysis. And again, you can check the script attached. You can invoke more information about the algorithm here and you see that there were no road messages in running the algorithm. And also you can have more information about what the algorithm was doing. And finally, using the command presees in the rethinking package, you can look at tables of the posterior distribution of the parameters. But this also provides some stick for the algorithm. In particular the R hat index here that you can see is one for all the three parameters of this model. The R hat statistic is basically an index of convergence of the algorithm. It compares the between and within chain estimates for model parameters. So if they agree, the Russia is going to be one as it is here. So R hat values larger than one actually indicate issues with convergence. And the recommendation is that the results should be used. The results of analysis should be used only if R hat is less than 1.05. Yeah, they're all one for all the parameters estimated. So that looks fine. And the other statistic reported here, ESS bulk is the bulk effective sample size, which is an index of the stability of the algorithm. The one recommendation is that bulk ESS should be at least 100 for each chain. So in this case I had six chains. And so I expected to have over 600 in the ESS in effective sample size bulk of these parameters. So these results also look good. And offers like cruise care emphasize the importance of reporting diagnostic information about the chains, the Markov chains you run. So this information should be reported in the results section or appendices. And it's also important to inspect the processes of the algorithm to check issues, to check for issues and diagnose potential problems and potential concerns. Chapter nine of statistical rethinking by Mekar Ra provides a clear guidance on these diagnostics and the R script I presented and some of the exercises attached with this module also provide some examples of other type of diagnostics for the chains and the estimation process. So having ensured that results are reliable and stable, we can look at the results. So here the precise command provides some tabular results. For example, the average mean of newborns birth weight for women of average weight is estimated to be 2900 grams with a standard deviation of 29 grams. And for each kilogram of maternal weight over the average weight, the baby birth weight is estimated, the baby's birth weight is estimated to increase by 5 grams. And this is a fact, this effect as a standard deviation equal to 2 grams. Also, you can see here in reported with percentages are the 89% credibility intervals, which basically tells that for example, the 99% of the times, there is 89% probability that the slope will range between 1.50 and 0.01. So you can see how these results also provide a very clear interpretation of these intervals, which is quite different from the confidence intervals reported in the standard approach. Here the credibility intervals, the 89% credibility intervals reported in this table, indicate the values that those parameters may take 89% of the times or with 89% probability. So the interpretation of these results is more intuitive and easier to communicate. And this is one of the advantages of a Bayesian approach. But as well as tables of results, plots are also very important in providing information about the results, particularly when the models are complex, for example, they include interactions. And plots also provide a way to informally check on the assumptions of the model. It's always recommended to plot the results from the posterior distribution. And in this graph here, I presented some of the results. So the dots represent the scatter of self data, where on the horizontal axis, I report the maternal weight in kilograms, and the vertical axis represents newborn's weight in grams. The darker line is the slope that presents the average intercept A and the average slope B extracted from the posterior distribution of the plausible combination of parameter values. So you can follow how I built this graph in the script attached with the material of this module. But one thing to keep in mind, however, is that in Bayesian analysis, this is just one of the most plausible lines that links the two variables. But there are many other lines that the model has ranked for their prosability and have high prosability as well as this line. So to make the most of the Bayesian approach, we shouldn't focus our inference only on one value or like these average values. And the posterior distribution, remember, considers and ranks every possible regression line and assigns relative prosability to each of these plausible regression lines. Therefore, there may be many other lines that have similar prosability than the average line shown here. And we need to explore the posterior probability of different combinations of parameters of A and B to have a sense of also how uncertain is the inference from our analysis. So it's important to make the most of the richness of Bayesian analysis to also investigate the uncertainty around the estimation of our parameters and ascertain it as I emphasized as also a more clear interpretation. And here in this graph I provide some examples of how to plot information about uncertainty in the distribution of combinations of different parameters according to the posterior distribution estimated, depending on the data and the models I had. Here in the graph on the right side, for example, you can see the shaded area that represents the 89% credibility intervals of the average slopes, of the average slopes. So that shaded area in light pink represents the values that the slope may take 89% of the time of 89% probability. And in the script attached with this module you can see how I estimated and created these graphs. The other graph on the right side represents also in the blue shaded area the 89% credibility intervals of the predicted newborn's birth weight. So it's basically representing that 89% probability of the birth weight taking different values according to this model. And you can also see in this way plotted against the observed data how the model assumptions fit in an informal way with the data. So these plots can be very useful in providing more information and more intuition about the model and how the model fits with the data. But at the same time we can use the posterior distribution of the parameters of the different combination of the parameters to also report other type of analysis and other information. For example, we may look at how likely birth weights are to be over certain value depending on conditionally on different maternal weights and so on. So there's a lot of different questions that can be answered by looking at the posterior distribution. And some of the references attached with this module also provide different examples where Bayesian analysis may be used to test different models and compare different models as well. So I refer to those references. So to conclude I wanted to highlight some of the key advantages of a Bayesian approach to regression analysis in my opinion. And one is that it's possible to incorporate previous knowledge which makes for more sensible models and the opportunity really to capitalize on the body of research that exists on a field. And I think this is very important in building better science in main ways. The other advantage I see is that also assumptions are formalized and therefore, first of all, there are no assumptions usually taken by default or as set by default as it might happen or it's more likely to happen in other approaches. And these assumptions are also easily reported and communicated using the type of notations I have used in these presentations. So for me, one of the advantages is also the transparency in reporting the models, the assumptions that are starting from in the analysis. And as long as they are transparently reported and then checked in sensitivity analysis, it makes sense to have sensible assumptions and more sensible models from which to start. The other advantage I see in Bayesian approaches to regression analysis is that every piece of information or data, however small, provide valid estimates. And this is because unlike in the standard approach to statistic and hypothesis testing, estimation in a Bayesian approach is not based on assumptions of underlying sampling distributions that are only plausible when samples are large or the so-called asymptotic behavior. So, however, small sample is, Bayesian estimates have a clear and valid interpretation. Obviously, there is a caveat and the caveat is that if the sample is small, the estimates are more dependent on the prior assumptions and if the prior is a bad one, the result in estimates based on small samples will be misleading. And finally, there is a great advantage in providing ranking of all the possibility of all the combination of parameter values. And as I try to emphasize the fact that we have a posterior probability of the different combination of parameter values allows to test and to report answers to different type of questions that are also more intuitive to explain and report to not just other researchers but laypersons. So, the type of inference and the type of messages that we can provide, it's also more intuitive. And again, it also focuses on issues of uncertainty and probability that allows to focus on the strength of effects, for example, in clearer ways and in ways that are more easily understandable for not just statisticians or researchers. So, this has been a very quick overview of regression models and there's a lot more to be said and done. But I hope this was useful. And if you found these presentations useful, please also look at the exercises I provided with this module. And for other material and other resources about research methods, please look at the web page of the National Center for Research Methods. Thank you very much. Bye.