Compare commits

..

No commits in common. "faafcd53fa2997776fb91477bbbdf9404098ee9b" and "015d1e46514259b41d7614a4ed1b0a08e831fdff" have entirely different histories.

3 changed files with 47 additions and 99 deletions

View file

@ -38,11 +38,6 @@
\sectionfont{\color{report_main}}
\subsectionfont{\color{report_third}}
%% Add pagebreak before each section
\let\oldsection\section
\renewcommand\section{\clearpage\oldsection}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This is where the actual document starts
%
@ -108,31 +103,22 @@ Hendrik Marcel W Tillemans\\
% You can just write text in here as you would in any other word processor.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Question 1}
This my answer to question 1.
\subsection{Example}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pagebreak
creates a page break.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Simulation Study}
\subsection{1.1: Generate Simulation Data}
We investigate a linear model with noise
\[y=\beta_0 + \beta_1 x1 + \beta_2 x2 + u\]
where
\[x1 \sim \mathcal{N}(3,\,6)\]
\[x2 \sim \mathcal{N}(3,\,6)\]
\[u \sim \mathcal{N}(0,\,3)\]
In figure \ref{fig::plot_1_1} we have a 3D representation of the generated model.
\begin{figure}[hb]
\includegraphics[width=0.6\paperwidth]{../figures/question_1_1}
\caption{Generated points for Question 1.1.}
\label{fig::plot_1_1}
\end{figure}
\subsection{1.2: Linear Fit on Generated Data}
\begin{table}[h]
@ -173,12 +159,6 @@ In figure \ref{fig::plot_1_1} we have a 3D representation of the generated model
\label{tab::table_1_6}
\end{table}
\begin{figure}[hb]
\includegraphics[width=0.6\paperwidth]{../figures/question_1_6}
\caption{Generated points for Question 1.6.}
\label{fig::plot_1_6}
\end{figure}
\section{examples}
Some greek letters:

View file

@ -1,14 +0,0 @@
\begin{tabular}{lrrrr}
\toprule
& Petal Width & Petal Length & Sepal Width & Sepal Length \\
\midrule
count & 150.000000 & 150.000000 & 150.000000 & 150.000000 \\
mean & 5.843333 & 3.057333 & 3.758000 & 1.199333 \\
std & 0.828066 & 0.435866 & 1.765298 & 0.762238 \\
min & 4.300000 & 2.000000 & 1.000000 & 0.100000 \\
25% & 5.100000 & 2.800000 & 1.600000 & 0.300000 \\
50% & 5.800000 & 3.000000 & 4.350000 & 1.300000 \\
75% & 6.400000 & 3.300000 & 5.100000 & 1.800000 \\
max & 7.900000 & 4.400000 & 6.900000 & 2.500000 \\
\bottomrule
\end{tabular}

View file

@ -65,22 +65,6 @@ np.random.seed(group_seed)
print_line_length = 90
print_line_start = 5
# -----------------------------------------------------------------------------
# Utility Functions for the Simulation
# -----------------------------------------------------------------------------
def results_to_latex_table_file(file_name, results, beta):
"""
This function takes a results object from statsmodels and writes it to a latex table file.
"""
d = {'True': beta,
'Estimated': results.params,
'Std Err': results.bse,
't-Stat': results.tvalues}
df = pd.DataFrame(data = d)
data_frame_to_latex_table_file(REPORT_DIR + file_name, df)
# -----------------------------------------------------------------------------
# 1.1
# -----------------------------------------------------------------------------
@ -106,21 +90,6 @@ x2 = rng.normal(2, 5, (num_obs,))
# y
y = beta[0] + beta[1]*x1 + beta[2]*x2 + u
# plot the resulting data
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
ax.scatter(x1, x2, y, marker='o')
ax.set_xlabel('x1')
ax.set_ylabel('x2')
ax.set_zlabel('y')
plt.savefig(FIGURE_DIR + "question_1_1.png")
plt.show()
# -----------------------------------------------------------------------------
# 1.2
# -----------------------------------------------------------------------------
@ -132,7 +101,12 @@ X = np.array([np.ones(num_obs), x1, x2]).T
m = sm.OLS(y, X)
# results =
results = m.fit()
results_to_latex_table_file('table_1_2.tex', results, beta)
d = {'True': beta,
'Estimated': results.params,
'Std Err': results.bse,
't-Stat': results.tvalues}
df = pd.DataFrame(data = d)
data_frame_to_latex_table_file(REPORT_DIR + 'table_1_2.tex', df)
# -----------------------------------------------------------------------------
# 1.3
@ -145,8 +119,12 @@ X = np.array([np.ones(num_obs), x1]).T
m = sm.OLS(y, X)
# results =
results = m.fit()
results_to_latex_table_file('table_1_3.tex', results, beta[0:2])
d = {'True': beta[0:2],
'Estimated': results.params,
'Std Err': results.bse,
't-Stat': results.tvalues}
df = pd.DataFrame(data = d)
data_frame_to_latex_table_file(REPORT_DIR + 'table_1_3.tex', df)
# -----------------------------------------------------------------------------
# 1.4
@ -163,7 +141,12 @@ X = np.array([np.ones(num_obs), x1, x2_new]).T
m = sm.OLS(y_new, X)
# results =
results = m.fit()
results_to_latex_table_file('table_1_4.tex', results, beta)
d = {'True': beta,
'Estimated': results.params,
'Std Err': results.bse,
't-Stat': results.tvalues}
df = pd.DataFrame(data = d)
data_frame_to_latex_table_file(REPORT_DIR + 'table_1_4.tex', df)
# -----------------------------------------------------------------------------
# 1.5
@ -176,31 +159,30 @@ X = np.array([np.ones(num_obs), x1]).T
m = sm.OLS(y_new, X)
# results =
results = m.fit()
results_to_latex_table_file('table_1_5.tex', results, beta[0:2])
d = {'True': beta[0:2],
'Estimated': results.params,
'Std Err': results.bse,
't-Stat': results.tvalues}
df = pd.DataFrame(data = d)
data_frame_to_latex_table_file(REPORT_DIR + 'table_1_5.tex', df)
# -----------------------------------------------------------------------------
# 1.6
# -----------------------------------------------------------------------------
# x1 --> x1_new so we can compare to the original x1 from 1.2
x1_new = rng.normal(3, 1, (num_obs,))
y_new = beta[0] + beta[1]*x1_new + beta[2]*x2 + u
x1 = rng.normal(3, 1, (num_obs,))
y = beta[0] + beta[1]*x1 + beta[2]*x2 + u
# X
X = np.array([np.ones(num_obs), x1_new, x2]).T
X = np.array([np.ones(num_obs), x1, x2]).T
# m
m = sm.OLS(y_new, X)
m = sm.OLS(y, X)
# results =
results = m.fit()
results_to_latex_table_file('table_1_6.tex', results, beta)
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.scatter(x1, y, c='b', marker="s", label='question 1.1')
ax1.scatter(x1_new, y_new, c='r', marker="o", label='question 1.6')
plt.legend(loc='upper left')
plt.savefig(FIGURE_DIR + "question_1_6.png")
plt.show()
d = {'True': beta,
'Estimated': results.params,
'Std Err': results.bse,
't-Stat': results.tvalues}
df = pd.DataFrame(data = d)
data_frame_to_latex_table_file(REPORT_DIR + 'table_1_6.tex', df)