1-1 Consider the case of P = 1 and x is a dummy variable, i.e., x 2 {0, 1}. Please show that the log-odds ratio under x = 1 and x = 0 is \(\beta_1\).

\(P(y=1|x=1)=\frac{exp(\beta_0+\beta_1)}{1+exp(\beta_0+\beta_1)}\)

\(P(y=0|x=1)=\frac{1}{1+exp(\beta_0+\beta_1)}\)

\(P(y=1|x=0)=\frac{exp(\beta_0)}{1+exp(\beta_0)}\)

\(P(y=0|x=0)=\frac{1}{1+exp(\beta_0)}\)

\(log(\frac{P(y=1|x=1)/P(y=0|x=1)}{P(y=1|x=0)/P(y=0|x=0)})=log(\frac{exp(\beta_0+\beta_1)}{exp(\beta_0)})=\beta_1\)


1-2 Let z denote a recoded reponse variable defined as z=1, if y=1, z=-1, if y=0. Please show that \(P(z|x)=\frac{1}{1+exp[-z(\beta_0+\sum_{p=1}^{P}\beta_p x_p)]}\)

\(P(z=1|x)=P(y=1|x)\) 經整理可得 \(P(z=1|x)=\frac{1}{1+exp(-(\beta_0+\sum_{p=1}^{P}\beta_p x_p))}\)

\(P(z=-1|x)=P(y=0|x)=\frac{1}{1+exp(\beta_0+\sum_{p=1}^{P}\beta_p x_p)}\)

由其中 \(\beta_0+\sum_{p=1}^{P}\beta_p x_p\) 正負項得知 \(P(z|x)=\frac{1}{1+exp[-z(\beta_0+\sum_{p=1}^{P}\beta_p x_p)]}\)


1-3 By using P(z|x), the negative log-likelihood function of \(\beta\) can be written as \(D(\beta)=\frac{1}{N}\sum_{n=1}^{N}log[1+exp(-z_nf(x_n))]\), where \(f(x)=\beta_0+\sum_{p=1}^{P}\beta_p x_p\). Please draw a plot with x-axis = \(zf(x)\) and y-axis = \(log[1+exp(-zf(x))]\).

\(w = zf(x)\), 那 y 可以寫成 \(y=log[1+exp(-w)]\)

y = function(w){log(1+exp(-w))}
plot(x=(-10:10),y=y(-10:10),type = "l",xlab = "zf(x)",ylab = "log[1+exp(-zf(x))]")