Skip to content

Instantly share code, notes, and snippets.

@SirmaXX
Last active April 28, 2022 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SirmaXX/f9e5518a9dfa21fc2e50dd24abf02f10 to your computer and use it in GitHub Desktop.
Save SirmaXX/f9e5518a9dfa21fc2e50dd24abf02f10 to your computer and use it in GitHub Desktop.
two column
# Multivariate Statisttics 7.Week Lecture Notes
# Multivariate Multiple Regression Analysis
You can find this topic in the chapter 8 in the book.
1. Multiple Regression
$$ Y = X\beta +\varepsilon ~~\to \text{Regression Model} $$
$$\varepsilon \to Error \\ ~~~~~~~X \to \text{data array } \\~~~ Y \to \text{Response}$$
$$ \hat{\beta} = (X^{'}X)^{-1}X^{'}Y ~~\to \text{Estimated regressions coefficients} $$
$$ \hat{Y} = X\hat{\beta} \to \text{Predicted response values} $$
## Example Application of Regression Analysis
```{r}
y<- c(1,4,3,8,9,4,6,3,7)
X <- c(rep(1,9),0,1,3,4,2,3,1,5,4)
X <- matrix(X, nrow= 9)
```
```{r}
X
```
```{r}
beta_hat <- solve(t(X)%*%X)%*%t(X)%*%y
beta_hat
```
The estimated regression model is $ Yhat= 3.965 + X\cdot 0.405 $
```{r}
prediction <- X%*%beta_hat
predictions <- data.frame(y=y,prediction=prediction)
predictions
```
<style>
.col2 {
columns: 2 200px; /* number of columns and width in pixels*/
-webkit-columns: 2 200px; /* chrome, safari */
-moz-columns: 2 200px; /* firefox */
}
</style>
<div class="col2">
Multiple Regression(çoklu)
$Y_1=\beta_0+\beta_1Z_{11}+..+\beta_1Z_{1r}Z_{1r}+\varepsilon_1$
$Y_2=\beta_0+\beta_1Z_{21}+..+\beta_1Z_{1r}Z_{2r}+\varepsilon_2$
$\vdots$
$Y_n=\beta_0+\beta_1Z_{n1}+..+\beta_1Z_{1r}Z_{nr}+\varepsilon_n$
Response~ Multiple_exp_variable
$\vdots$
$\vdots$
```
```
Multivarite(Multiple)Regression(Çok değişkenli Çoklu Regresyon)
$Y_1=\beta_{01}+\beta_{11}Z_{1}+...+\beta_{r1}Z_{r}+\varepsilon_1$
$Y_2=\beta_{02}+\beta_{12}Z_{1}+...+\beta_{r2}Z_{r}+\varepsilon_2$
$\vdots$
$Y_n =\beta_{0n}+\beta_{1n}Z_{1}+...+\beta_{rn}Z_{r}+\varepsilon_n$
M response variables~explanotary variables(#1)
The error term $\varepsilon'=[\varepsilon_1,\varepsilon_2,...,\varepsilon_m]$ has $E(\varepsilon)=\mathbf{0}$ and $var(\varepsilon)=\Sigma$ Thus ,the terms associated with different responses may be
```
```
</div>
Explanort variables matrix
$$Z_{nx(n+1)}=\begin{bmatrix}
Z_{10} & Z_{11} & \dots &Z_{1r}\\
Z_{20} & Z_{21} & \dots &Z_{2r}\\
\vdots & \dots & \dots &\dots\\
Z_{n0} & Z_{n1} & \dots &Z_{nr}\\
\end{bmatrix}_{nx(r+1)} \\$$
Responses matrix
$$\_{nxm}=\begin{bmatrix}
Y_{11} & Y_{11} & \dots &Y_{1m}\\
Z_{21} & Z_{21} & \dots &Z_{2m}\\
\vdots & \dots & \dots &\dots\\
Z_{n1} & Z_{n2} & \dots &Z_{nm}\\
\end{bmatrix}_{nxm} \\$$
Epsilon(errors)
$$\epsilon=\begin{bmatrix}
\epsilon_{11} & \epsilon_{11} & \dots &\epsilon_{1m}\\
\epsilon_{21} & \epsilon_{21} & \dots &\epsilon_{2m}\\
\vdots & \dots & \dots &\dots\\
\epsilon_{n1} & \epsilon_{n2} & \dots &\epsilon_{nm}\\
\end{bmatrix}_{nxm} \\$$
$$\beta=\begin{bmatrix}
\beta_{01} & \beta{01} & \dots &\beta_{0m}\\
\beta_{11} & \beta_{12} & \dots &\beta_{1m}\\
\vdots & \dots & \dots &\dots\\
\beta_{r1} & \beta_{r2} & \dots &\beta_{rm}\\
\end{bmatrix}_{rxm} \\$$
$$\beta =[\beta_{1},\beta_{2},...,\beta_{n}]$$
Regression models
$$\mathbf(Y)_{nxm}=\mathbf(Z)_{nx(n+1)}+\mathbf(\beta)_{rxm}+ \mathbf(\epsilon)_{nxm}$$
$$ betahats=(Z'Z)^-1Z'Y_{i} $$
yhat
$$ Yhats=Z betahat $$
infect you fit m different regression models
$$Y_{İ}=ZBİ+epsiloni , i=1,...,m $$
input the datasets
```{r}
Y1=c(32,47,54,60,45,27,38,46) #1ST response variable
Y2=c(27,41,40,52,30,18,21,18) #2ST response variable
x1=c(4,8,6,5,9,6,11,10) #1ST explonatory variable
X2=c(13,18,17,20,14,8,9,7) #2ST explonatory variable
```
organize Y and Z
```{r}
Y1=c(32,47,54,60,45,27,38,46) #1ST response variable
Y2=c(27,41,40,52,30,18,21,18) #2ST response variable
x1=c(4,8,6,5,9,6,11,10) #1ST explonatory variable
x2=c(13,18,17,20,14,8,9,7) #2ST explonatory variable
```
find bhat six beta coeffiencet
```{r}
(Y<-matrix(c(Y1,Y2),nrow = 8,ncol=2))
(Z<-matrix(c(rep(1,8) ,x1,x2),nrow = 8,ncol=3))
(bhat<-solve(t(Z) %*% Z)%*% t(Z) %*% Y)
```
our models here
$$Y_1hat=2.6995+1.8780x1+2.043x2$$
$$Y_2hat=-3.3458+0.1295x1+2.043x2$$
yhats are ztimesbhat
Explanort variables matrix
$$Z_{nx(n+1)}=\begin{bmatrix}
Z_{10} & Z_{11} & \dots &Z_{1r}\\
Z_{20} & Z_{21} & \dots &Z_{2r}\\
\vdots & \dots & \dots &\dots\\
Z_{n0} & Z_{n1} & \dots &Z_{nr}\\
\end{bmatrix}_{nx(r+1)} \\$$
Responses matrix
$$\_{nxm}=\begin{bmatrix}
Y_{11} & Y_{11} & \dots &Y_{1m}\\
Z_{21} & Z_{21} & \dots &Z_{2m}\\
\vdots & \dots & \dots &\dots\\
Z_{n1} & Z_{n2} & \dots &Z_{nm}\\
\end{bmatrix}_{nxm} \\$$
Epsilon(errors)
$$\epsilon=\begin{bmatrix}
\epsilon_{11} & \epsilon_{11} & \dots &\epsilon_{1m}\\
\epsilon_{21} & \epsilon_{21} & \dots &\epsilon_{2m}\\
\vdots & \dots & \dots &\dots\\
\epsilon_{n1} & \epsilon_{n2} & \dots &\epsilon_{nm}\\
\end{bmatrix}_{nxm} \\$$
$$\beta=\begin{bmatrix}
\beta_{01} & \beta{01} & \dots &\beta_{0m}\\
\beta_{11} & \beta_{12} & \dots &\beta_{1m}\\
\vdots & \dots & \dots &\dots\\
\beta_{r1} & \beta_{r2} & \dots &\beta_{rm}\\
\end{bmatrix}_{rxm} \\$$
$$\beta =[\beta_{1},\beta_{2},...,\beta_{n}]$$
Regression models
$$\mathbf(Y)_{nxm}=\mathbf(Z)_{nx(n+1)}+\mathbf(\beta)_{rxm}+ \mathbf(\epsilon)_{nxm}$$
betahats
<style>
.col2 {
columns: 2 200px; /* number of columns and width in pixels*/
-webkit-columns: 2 200px; /* chrome, safari */
-moz-columns: 2 200px; /* firefox */
}
</style>
<div class="col2">
firtst
$Y_1=\beta_0+\beta_1Z_{11}+..+\beta_1Z_{1r}Z_{1r}+\varepsilon
```
```
second column
```
```
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment