--- title: "Fitting a logistic regression" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Fitting a logistic regression} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ``` This example describes how to perform a Bayesian logistic regression using the malt function from the malt library. For an explanation on how to use the malt function see different vignette. ```{r setup} library(malt) ``` We are given $n$ data-points which have $d$ real-valued explanatory variables, summarised in a matrix $X\in\mathbb{R}^{n\times d}$ and a vector of response variables $Y\in\{0,1\}^{n}$. We want to find the $\theta\in\mathbb{R}^d$ such that $(1+\exp(-\theta^\top X_i))^{-1}$ is a good predictor of the probability of $Y_i=1$. We pick $X$ and a true $\theta$ and generate synthetic data $Y$, which we then try to recover: ```{r} d=2 n=1000 X=matrix(rnorm(n*d),nr=n,nc=d) true_theta=rep(1,d) p=1/(1+exp(-X%*%true_theta)) Y=as.numeric(runif(length(p))