% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
  8pt,
  ignorenonframetext,
]{beamer}
\author{}
\date{\vspace{-2.5em}}

\usepackage{pgfpages}
\setbeamertemplate{caption}[numbered]
\setbeamertemplate{caption label separator}{: }
\setbeamercolor{caption name}{fg=normal text.fg}
\beamertemplatenavigationsymbolsempty
% Prevent slide breaks in the middle of a paragraph
\widowpenalties 1 10000
\raggedbottom
\setbeamertemplate{part page}{
  \centering
  \begin{beamercolorbox}[sep=16pt,center]{part title}
    \usebeamerfont{part title}\insertpart\par
  \end{beamercolorbox}
}
\setbeamertemplate{section page}{
  \centering
  \begin{beamercolorbox}[sep=12pt,center]{part title}
    \usebeamerfont{section title}\insertsection\par
  \end{beamercolorbox}
}
\setbeamertemplate{subsection page}{
  \centering
  \begin{beamercolorbox}[sep=8pt,center]{part title}
    \usebeamerfont{subsection title}\insertsubsection\par
  \end{beamercolorbox}
}
\AtBeginPart{
  \frame{\partpage}
}
\AtBeginSection{
  \ifbibliography
  \else
    \frame{\sectionpage}
  \fi
}
\AtBeginSubsection{
  \frame{\subsectionpage}
}
\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\usepackage{iftex}
\ifPDFTeX
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math}
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
  hidelinks,
  pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\newif\ifbibliography
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
% type setting
% ------------------------------------------------------------------------------
\usepackage[german]{babel}     

% fonts
% ------------------------------------------------------------------------------
\usefonttheme{professionalfonts}

% slide title and horizontal line
% ------------------------------------------------------------------------------
\setbeamertemplate{frametitle}{%
    \vskip-30pt \color{black}\large%
    \begin{minipage}[b][23pt]{120mm}%
    \flushleft\insertframetitle%
    \end{minipage}%
}

\setbeamertemplate{headline}										
{
\vskip10pt\hfill\hspace{3.5mm} 										 
\vskip15pt\color{black}\rule{\textwidth}{0.4pt} 					 
}

% slide number
% ---------------------------------------------------------------
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{footline}
{
\vskip5pt
\vskip2pt
\makebox[123mm]{\hspace{7.5mm}
\hfill Programmierung und Deskriptive Statistik $\vert$ 
\copyright $ $ 2022 Dirk Ostwald CC BY-NC-SA 4.0 $\vert$ 
Folie \insertframenumber}
\vskip4pt
}

% block color scheme
% ------------------------------------------------------------------------------
% colors
\definecolor{white}{RGB}{255,255,255}
\definecolor{grey}{RGB}{235,235,235}
\definecolor{lightgrey}{RGB}{245,245,245}
\definecolor{LightBlue}{RGB}{220,220,255}
\definecolor{darkblue}{RGB}{51, 51, 153}

% definitions and theorems
\setbeamercolor{block title}{fg = black, bg = grey}
\setbeamercolor{block body}{fg = black, bg = lightgrey}

% general line spacing 
% ------------------------------------------------------------------------------
\linespread{1.3}

% local line spacing
% ------------------------------------------------------------------------------
\usepackage{setspace}

% colors
% -----------------------------------------------------------------------------
\usepackage{color}

% justified text
% ------------------------------------------------------------------------------
\usepackage{ragged2e}
\usepackage{etoolbox}
\apptocmd{\frame}{}{\justifying}{}

% bullet point lists
% -----------------------------------------------------------------------------
\setbeamertemplate{itemize item}[circle]
\setbeamertemplate{itemize subitem}[circle]
\setbeamertemplate{itemize subsubitem}[circle]
\setbeamercolor{itemize item}{fg = black}
\setbeamercolor{itemize subitem}{fg = black}
\setbeamercolor{itemize subsubitem}{fg = black}
\setbeamercolor{enumerate item}{fg = black}
\setbeamercolor{enumerate subitem}{fg = black}
\setbeamercolor{enumerate subsubitem}{fg = black}
\setbeamerfont{itemize/enumerate body}{}
\setbeamerfont{itemize/enumerate subbody}{size = \normalsize}
\setbeamerfont{itemize/enumerate subsubbody}{size = \normalsize}

% color links
% ------------------------------------------------------------------------------
\usepackage{hyperref}
\definecolor{urls}{RGB}{204,0,0}
\hypersetup{colorlinks, citecolor = darkblue, urlcolor = urls}


% additional math commands
% ------------------------------------------------------------------------------
\usepackage{bm}                                         % bold math symbols
\newcommand{\niton}{\not\owns}

% text highlighting
% ------------------------------------------------------------------------------
\usepackage{soul}
\makeatletter
\let\HL\hl
\renewcommand\hl{%
  \let\set@color\beamerorig@set@color
  \let\reset@color\beamerorig@reset@color
  \HL}
\makeatother

% equation highlighting
% -----------------------------------------------------------------------------
\newcommand{\highlight}[2][yellow]{\mathchoice%
  {\colorbox{#1}{$\displaystyle#2$}}%
  {\colorbox{#1}{$\textstyle#2$}}%
  {\colorbox{#1}{$\scriptstyle#2$}}%
  {\colorbox{#1}{$\scriptscriptstyle#2$}}}%

% additional mathematical operators
% ------------------------------------------------------------------------------
\DeclareMathOperator*{\argmax}{arg\,max}
\DeclareMathOperator*{\argmin}{arg\,min}

\ifLuaTeX
  \usepackage{selnolig}  % disable illegal ligatures
\fi

\begin{document}

\begin{frame}[plain]{}
\protect\hypertarget{section}{}
\center

\begin{center}\includegraphics[width=0.2\linewidth]{4_Abbildungen/pds_4_otto} \end{center}

\vspace{2mm}

\huge

Programmierung und Deskriptive Statistik \vspace{6mm}

\large

BSc Psychologie WiSe 2021/22

\vspace{6mm}
\large

Prof.~Dr.~Dirk Ostwald
\end{frame}

\begin{frame}[plain]{}
\protect\hypertarget{section-1}{}
\vfill
\huge
\begin{center}
(4) Matrizen
\end{center}
\vfill
\end{frame}

\begin{frame}[plain]{}
\protect\hypertarget{section-2}{}
Programmierung und Deskriptive Statistik

\small
\center
\footnotesize
\renewcommand{\arraystretch}{1.1}
\begin{tabular}{lll}
Datum        & Einheit                     & Thema                                              \\\hline
14.10.2021   & Einführung                  & (1) Einführung                                     \\
21.10.2021   & R Grundlagen                & (2) R und RStudio                          \\
28.10.2021   & R Grundlagen                & (3) R und RStudio                          \\
04.11.2021   & R Grundlagen                & (4) Vektoren                               \\
  \textbf{11.11.2021}
& \textbf{R Grundlagen}
& \textbf{(5) Matrizen}                                                      \\
18.11.2021   & R Grundlagen                & (6) Listen und Dataframes                  \\
25.11.2021   & R Grundlagen                & (7) Kontrollstruktur und Schleifen         \\
02.12.2021   & R Grundlagen                & (8) R Base Graphics                        \\
09.12.2021   & Deskriptive Statistik       & (9) Datenmanagement                        \\
16.12.2021   & Deskriptive Statistik       & (10) Häufigkeitsverteilungen               \\
             & \textcolor{gray}{Weihnachtspause}                                        \\
06.01.2022   & Deskriptive Statistik       & (11) Verteilungsfunktionen und Quantile    \\
13.01.2022   & Deskriptive Statistik       & (12) Maße der zentralen Tendenz            \\
20.01.2022   & Deskriptive Statistik       & (13) Maße der Datenvariabilität            \\
27.01.2022   & Deskriptive Statistik       & (14) Bivariate Zusammenhangsmaße           \\\hline
  \textbf{25.02.2021}  
& \textbf{Klausurtermin}
& \textbf{9 - 10 Uhr, G26 - H11}                                                        \\
Jul 2022     & Klausurwiederholungstermin
\end{tabular}
\end{frame}

\begin{frame}{}
\protect\hypertarget{section-3}{}
\setstretch{3}
\vfill
\large

Matrizen

Übungen und Selbstkontrollfragen \vfill
\end{frame}

\begin{frame}{}
\protect\hypertarget{section-4}{}
\setstretch{3}
\vfill
\large

\textbf{Matrizen}

Übungen und Selbstkontrollfragen \vfill
\end{frame}

\begin{frame}{Matrizen}
\protect\hypertarget{matrizen}{}
\setstretch{1.5}

\textcolor{darkblue}{Übersicht} \small

Matrizen sind zweidimensionale, rechteckige Datenstrukturen der Form

\footnotesize

\begin{equation}
M = \begin{pmatrix}
m_{11}      & m_{12}    & \cdots    & m_{1n_c}          \\
m_{21}      & m_{22}    & \cdots    & m_{2n_c}          \\
\vdots      & \vdots    & \ddots    & \vdots            \\
m_{n_r1}    & m_{n_r2}  & \cdots    & {m_{n_rn_c}}          \\
\end{pmatrix}
\end{equation}

\small

\begin{itemize}
\tightlist
\item
  Die Elemente \(m_{ij}, i = 1,...,n_r, j = 1,...,n_c\) sind vom
  gleichen Typ.
\item
  \(n_r\) ist die Anzahl der Zeilen (rows), \(n_c\) ist die Anzahl der
  Spalten (columns).
\item
  Jedes Element einer Matrix hat einen Zeilenindex \(i\) und einen
  Spaltenindex \(j\).
\item
  Intuitiv sind Matrizen numerisch indizierte Tabellen.
\item
  Formal sind Matrizen in R zweidimensional interpretierte atomare
  Vektoren.
\item
  Matrizen in R sind nicht identisch mit dem mathematischen
  Matrixbegriff.
\item
  Matrizen in R können allerdings für Lineare Algebra verwendet werden.
\item
  Lineare Algebra ist die Sprache (linearer) statistischer Modelle.
\end{itemize}
\end{frame}

\begin{frame}[fragile]{Matrizen}
\protect\hypertarget{matrizen-1}{}
\setstretch{1.2}

\textcolor{darkblue}{Erzeugung}

Die \texttt{matrix()} Funktion befüllt Matrizen mit Vektorelementen
\small

\texttt{matrix(data,\ nrow,\ ncol,\ byrow)}

\footnotesize

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{matrix}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{12}\NormalTok{), }\AttributeTok{nrow =} \DecValTok{3}\NormalTok{)             }\CommentTok{\# 3 x 4 Matrix der Zahlen 1,...,12, byrow = F}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
>      [,1] [,2] [,3] [,4]
> [1,]    1    4    7   10
> [2,]    2    5    8   11
> [3,]    3    6    9   12
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{matrix}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{12}\NormalTok{), }\AttributeTok{ncol =} \DecValTok{4}\NormalTok{)             }\CommentTok{\# 3 x 4 Matrix der Zahlen 1,...,12, byrow = F}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
>      [,1] [,2] [,3] [,4]
> [1,]    1    4    7   10
> [2,]    2    5    8   11
> [3,]    3    6    9   12
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{matrix}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{12}\NormalTok{), }\AttributeTok{nrow =} \DecValTok{3}\NormalTok{, }\AttributeTok{byrow =}\NormalTok{ T)  }\CommentTok{\# 3 x 4 Matrix der Zahlen 1,...,12, byrow = T}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
>      [,1] [,2] [,3] [,4]
> [1,]    1    2    3    4
> [2,]    5    6    7    8
> [3,]    9   10   11   12
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{Matrizen}
\protect\hypertarget{matrizen-2}{}
\setstretch{1.2}

\textcolor{darkblue}{Erzeugung} \vspace{2mm} \small Die Funktion
\texttt{cbind()} konkateniert passende Matrizen spaltenweise

\footnotesize

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{A }\OtherTok{=} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{4}\NormalTok{) , }\AttributeTok{nrow =} \DecValTok{2}\NormalTok{)       }\CommentTok{\# 2 x 2 Matrix der Zahlen 1,...,4}
\FunctionTok{print}\NormalTok{(A)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
>      [,1] [,2]
> [1,]    1    3
> [2,]    2    4
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{B }\OtherTok{=} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{5}\SpecialCharTok{:}\DecValTok{10}\NormalTok{), }\AttributeTok{nrow =} \DecValTok{2}\NormalTok{)       }\CommentTok{\# 2 x 3 Matrix der Zahlen 5,...,10}
\FunctionTok{print}\NormalTok{(B)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
>      [,1] [,2] [,3]
> [1,]    5    7    9
> [2,]    6    8   10
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{C }\OtherTok{=} \FunctionTok{cbind}\NormalTok{(A,B)                      }\CommentTok{\# spaltenweise Konkatenierung von A und B}
\FunctionTok{print}\NormalTok{(C)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
>      [,1] [,2] [,3] [,4] [,5]
> [1,]    1    3    5    7    9
> [2,]    2    4    6    8   10
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{Matrizen}
\protect\hypertarget{matrizen-3}{}
\setstretch{1.2}

\textcolor{darkblue}{Erzeugung} \vspace{2mm} \small Die Funktion
\texttt{rbind()} konkateniert passende Matrizen reihenweise

\footnotesize

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{A }\OtherTok{=} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{6}\NormalTok{) , }\AttributeTok{nrow =} \DecValTok{2}\NormalTok{, }\AttributeTok{byrow =}\NormalTok{ T)  }\CommentTok{\# 2 x 3 Matrix der Zahlen 1,...,6}
\FunctionTok{print}\NormalTok{(A)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
>      [,1] [,2] [,3]
> [1,]    1    2    3
> [2,]    4    5    6
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{B }\OtherTok{=} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{7}\SpecialCharTok{:}\DecValTok{9}\NormalTok{), }\AttributeTok{nrow =} \DecValTok{1}\NormalTok{)              }\CommentTok{\# 1 x 3 Matrix der Zahlen 5,...,10}
\FunctionTok{print}\NormalTok{(B)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
>      [,1] [,2] [,3]
> [1,]    7    8    9
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{C }\OtherTok{=} \FunctionTok{rbind}\NormalTok{(A,B)                            }\CommentTok{\# reihenweise Konkatenierung von A und B}
\FunctionTok{print}\NormalTok{(C)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
>      [,1] [,2] [,3]
> [1,]    1    2    3
> [2,]    4    5    6
> [3,]    7    8    9
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{Matrizen}
\protect\hypertarget{matrizen-4}{}
\textcolor{darkblue}{Charakterisierung} \vspace{2mm}

\small

\texttt{typeof()}gibt den elementaren Datentyp einer Matrix aus

\footnotesize

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{A }\OtherTok{=} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{c}\NormalTok{(T,T,F,F), }\AttributeTok{nrow =} \DecValTok{2}\NormalTok{)          }\CommentTok{\# 2 x 2 Matrix von Elementen vom Typ logical}
\FunctionTok{typeof}\NormalTok{(A)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
> [1] "logical"
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{B }\OtherTok{=} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\StringTok{"a"}\NormalTok{,}\StringTok{"b"}\NormalTok{,}\StringTok{"c"}\NormalTok{), }\AttributeTok{nrow =} \DecValTok{1}\NormalTok{)      }\CommentTok{\# 1 x 3 Matrix von Elementen vom Typ character}
\FunctionTok{typeof}\NormalTok{(B)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
> [1] "character"
\end{verbatim}

\small

\texttt{nrow()} und \texttt{ncol()} geben die Zeilen- bzw. Spaltenanzahl
aus

\footnotesize

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{C }\OtherTok{=} \FunctionTok{matrix}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{12}\NormalTok{, }\AttributeTok{nrow =} \DecValTok{3}\NormalTok{)                }\CommentTok{\# 3 x 4 Matrix}
\FunctionTok{nrow}\NormalTok{(C)                                   }\CommentTok{\# Anzahl Zeilen}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
> [1] 3
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{ncol}\NormalTok{(C)                                   }\CommentTok{\# Anzahl Spalten}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
> [1] 4
\end{verbatim}
\end{frame}

\begin{frame}[fragile]{Matrizen}
\protect\hypertarget{matrizen-5}{}
\textcolor{darkblue}{Indizierung} \vspace{1mm}

Generell gilt \small

\begin{itemize}
\tightlist
\item
  Matrixelemente werden mit einen Zeilenindex und einem Spaltenindex
  indiziert.
\item
  Die Indexreihenfolge ist immer 1. Zeile, 2. Spalte.
\item
  Die Prinzipien der Indizierung entsprechen der Vektorindizierung.
\item
  Indizes verschiedener Dimensionen können unterschiedlich indiziert
  werden.
\item
  Eindimensionale Resultate liegen als Vektor, nicht als Matrix vor.
\end{itemize}

\footnotesize

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{A }\OtherTok{=} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{2}\SpecialCharTok{:}\DecValTok{7}\NormalTok{)}\SpecialCharTok{\^{}}\DecValTok{2}\NormalTok{, }\AttributeTok{nrow =} \DecValTok{2}\NormalTok{)      }\CommentTok{\# 2 x 3 Matrix der Zahlen 2\^{}2,...,7\^{}2}
\FunctionTok{print}\NormalTok{(A)}
\NormalTok{a\_13  }\OtherTok{=}\NormalTok{ A[}\DecValTok{1}\NormalTok{,}\DecValTok{3}\NormalTok{]                      }\CommentTok{\# Element in 1. Zeile, 3. Spalte von A [36]}
\NormalTok{a\_22  }\OtherTok{=}\NormalTok{ A[}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{]                      }\CommentTok{\# Element in 2. Zeile, 2. Spalte von A [35]}
\NormalTok{a\_2.  }\OtherTok{=}\NormalTok{ A[}\DecValTok{2}\NormalTok{,]                       }\CommentTok{\# Alle Elemente der 2. Zeile [9,25,49]}
\NormalTok{a\_}\FloatTok{.3}  \OtherTok{=}\NormalTok{ A[,}\DecValTok{3}\NormalTok{]                       }\CommentTok{\# Alle Elemente der 3. Spalte [36,49]}
\NormalTok{A\_12  }\OtherTok{=}\NormalTok{ A[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{2}\NormalTok{,}\DecValTok{1}\SpecialCharTok{:}\DecValTok{2}\NormalTok{]                  }\CommentTok{\# Submatrix der ersten zwei Zeilen und Spalten}
\NormalTok{A10   }\OtherTok{=}\NormalTok{ A[A}\SpecialCharTok{\textgreater{}}\DecValTok{10}\NormalTok{]                     }\CommentTok{\# Elemente von A groesser 10 [16,25,36,49]}
\NormalTok{A\_13  }\OtherTok{=}\NormalTok{ A[}\DecValTok{1}\NormalTok{,}\FunctionTok{c}\NormalTok{(F,F,T)]               }\CommentTok{\# Element in 1. Zeile, 3. Spalte von A [36]}
\end{Highlighting}
\end{Shaded}
\end{frame}

\begin{frame}[fragile]{Matrizen}
\protect\hypertarget{matrizen-6}{}
\textcolor{darkblue}{Arithmetik} \vspace{2mm}

\small

Unitäre arithmetische Operatoren und Funktionen werden elementweise
ausgewertet

\footnotesize

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{A }\OtherTok{=} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{4}\NormalTok{), }\AttributeTok{nrow =} \DecValTok{2}\NormalTok{)    }\CommentTok{\# 2 x 2 Matrix der Zahlen 1,2,3,4}
\NormalTok{     [,}\DecValTok{1}\NormalTok{] [,}\DecValTok{2}\NormalTok{]}
\NormalTok{[}\DecValTok{1}\NormalTok{,]    }\DecValTok{1}    \DecValTok{3}
\NormalTok{[}\DecValTok{2}\NormalTok{,]    }\DecValTok{2}    \DecValTok{4}

\NormalTok{B }\OtherTok{=}\NormalTok{ A}\SpecialCharTok{\^{}}\DecValTok{2}                         \CommentTok{\# B[i,j]  = A[i,j]\^{}2,  1 \textless{}= i,j \textless{}= 2}
\NormalTok{     [,}\DecValTok{1}\NormalTok{] [,}\DecValTok{2}\NormalTok{]}
\NormalTok{[}\DecValTok{1}\NormalTok{,]    }\DecValTok{1}    \DecValTok{9}                  \CommentTok{\# 1\^{}2, 3\^{}2}
\NormalTok{[}\DecValTok{2}\NormalTok{,]    }\DecValTok{4}   \DecValTok{16}                  \CommentTok{\# 2\^{}2, 4\^{}2}

\NormalTok{C }\OtherTok{=} \FunctionTok{sqrt}\NormalTok{(B)                     }\CommentTok{\# C[i,j]  = sqrt(A[i,j]\^{}2),  1 \textless{}= i,j \textless{}= 2}
\NormalTok{     [,}\DecValTok{1}\NormalTok{] [,}\DecValTok{2}\NormalTok{]}
\NormalTok{[}\DecValTok{1}\NormalTok{,]    }\DecValTok{1}    \DecValTok{3}                  \CommentTok{\# sqrt(1\^{}2), sqrt(3\^{}2)}
\NormalTok{[}\DecValTok{2}\NormalTok{,]    }\DecValTok{2}    \DecValTok{4}                  \CommentTok{\# sqrt(2\^{}2), sqrt(4\^{}2)}

\NormalTok{D }\OtherTok{=} \FunctionTok{exp}\NormalTok{(A)                      }\CommentTok{\# D[i,j] = exp(A[i,j]),  1 \textless{}= i,j \textless{}= 2}
\NormalTok{     [,}\DecValTok{1}\NormalTok{] [,}\DecValTok{2}\NormalTok{]}
\NormalTok{[}\DecValTok{1}\NormalTok{,]  }\FloatTok{2.7}  \FloatTok{20.0}                 \CommentTok{\# exp(1), exp(3)}
\NormalTok{[}\DecValTok{2}\NormalTok{,]  }\FloatTok{7.4}  \FloatTok{54.6}                 \CommentTok{\# exp(2), exp(4)}
\end{Highlighting}
\end{Shaded}
\end{frame}

\begin{frame}[fragile]{Matrizen}
\protect\hypertarget{matrizen-7}{}
\textcolor{darkblue}{Arithmetik} \vspace{2mm}

\small

Matrizen passender Größe können mit binären arithmetischen Operatoren
verknüpft werden

Binäre arithmetische Operatoren +,-,*,\textbackslash werden bei gleicher
Größe elementweise ausgewertet

\vspace{1mm}
\footnotesize

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{A }\OtherTok{=} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{4}\NormalTok{), }\AttributeTok{nrow =} \DecValTok{2}\NormalTok{)    }\CommentTok{\# 2 x 2 Matrix der Zahlen 1,2,3,4}
\NormalTok{     [,}\DecValTok{1}\NormalTok{] [,}\DecValTok{2}\NormalTok{]}
\NormalTok{[}\DecValTok{1}\NormalTok{,]    }\DecValTok{1}    \DecValTok{3}
\NormalTok{[}\DecValTok{2}\NormalTok{,]    }\DecValTok{2}    \DecValTok{4}

\NormalTok{B }\OtherTok{=} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{5}\SpecialCharTok{:}\DecValTok{8}\NormalTok{), }\AttributeTok{nrow =} \DecValTok{2}\NormalTok{)    }\CommentTok{\# 2 x 2 Matrix der Zahlen 5,6,7,8}
\NormalTok{     [,}\DecValTok{1}\NormalTok{] [,}\DecValTok{2}\NormalTok{]}
\NormalTok{[}\DecValTok{1}\NormalTok{,]    }\DecValTok{5}    \DecValTok{7}
\NormalTok{[}\DecValTok{2}\NormalTok{,]    }\DecValTok{6}    \DecValTok{8}

\NormalTok{C }\OtherTok{=}\NormalTok{ A }\SpecialCharTok{+}\NormalTok{ B                       }\CommentTok{\# C[i,j] = A[i,j] + B[i,j], 1 \textless{}= i,j \textless{}= 2}
\NormalTok{     [,}\DecValTok{1}\NormalTok{] [,}\DecValTok{2}\NormalTok{]}
\NormalTok{[}\DecValTok{1}\NormalTok{,]    }\DecValTok{6}   \DecValTok{10}                  \CommentTok{\# 1 + 5, 3 + 7}
\NormalTok{[}\DecValTok{2}\NormalTok{,]    }\DecValTok{8}   \DecValTok{12}                  \CommentTok{\# 2 + 6, 4 + 8}

\NormalTok{D }\OtherTok{=}\NormalTok{ A }\SpecialCharTok{*}\NormalTok{ B}
\NormalTok{     [,}\DecValTok{1}\NormalTok{] [,}\DecValTok{2}\NormalTok{]}
\NormalTok{[}\DecValTok{1}\NormalTok{,]    }\DecValTok{5}   \DecValTok{21}                  \CommentTok{\# 1 * 5, 3 * 7}
\NormalTok{[}\DecValTok{2}\NormalTok{,]   }\DecValTok{12}   \DecValTok{32}                  \CommentTok{\# 2 * 6, 4 * 8}
\end{Highlighting}
\end{Shaded}
\end{frame}

\begin{frame}[fragile]{Matrizen}
\protect\hypertarget{matrizen-8}{}
\textcolor{darkblue}{Arithmetik} \vspace{1mm} \small

Mit R Matrizen kann Lineare Algebra betrieben werden

\begin{itemize}
\tightlist
\item
  Addition, Subtraktion, Hadamardprodukt elementweise definiert wie oben
\item
  Matrixmultiplikation, Transposition, Inversion, Determinante
\end{itemize}

\vspace{1mm}
\footnotesize

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{C }\OtherTok{=}\NormalTok{ A  }\SpecialCharTok{\% * \%}\NormalTok{ B                  }\CommentTok{\# 2 x 2 Matrixprodukt}
\NormalTok{      [,}\DecValTok{1}\NormalTok{] [,}\DecValTok{2}\NormalTok{]}
\NormalTok{[}\DecValTok{1}\NormalTok{,]   }\DecValTok{23}   \DecValTok{31}                  \CommentTok{\# 1*5 + 3*6, 1*7+3*8}
\NormalTok{[}\DecValTok{2}\NormalTok{,]   }\DecValTok{34}   \DecValTok{46}                  \CommentTok{\# 2*5 + 4*6, 2*7+4*8}

\NormalTok{A\_T }\OtherTok{=} \FunctionTok{t}\NormalTok{(A)                      }\CommentTok{\# Transposition von A}
\NormalTok{      [,}\DecValTok{1}\NormalTok{] [,}\DecValTok{2}\NormalTok{]}
\NormalTok{[}\DecValTok{1}\NormalTok{,]   }\DecValTok{1}   \DecValTok{2}                    \CommentTok{\# A[1,1], A[2,1]}
\NormalTok{[}\DecValTok{2}\NormalTok{,]   }\DecValTok{3}   \DecValTok{4}                    \CommentTok{\# A[1,2], A[2,2]}

\NormalTok{A\_inv }\OtherTok{=} \FunctionTok{solve}\NormalTok{(A)                }\CommentTok{\# Inverse von A}
\NormalTok{     [,}\DecValTok{1}\NormalTok{] [,}\DecValTok{2}\NormalTok{]}
\NormalTok{[}\DecValTok{1}\NormalTok{,]   }\SpecialCharTok{{-}}\DecValTok{2}  \FloatTok{1.5}
\NormalTok{[}\DecValTok{2}\NormalTok{,]    }\DecValTok{1} \SpecialCharTok{{-}}\FloatTok{0.5}

\NormalTok{A\_det }\OtherTok{=} \FunctionTok{det}\NormalTok{(A)                  }\CommentTok{\# Determinante von A}
\NormalTok{[}\DecValTok{1}\NormalTok{] }\SpecialCharTok{{-}}\DecValTok{2}                          \CommentTok{\# 1*4 {-} 2*3}
\end{Highlighting}
\end{Shaded}
\end{frame}

\begin{frame}[fragile]{Matrizen}
\protect\hypertarget{matrizen-9}{}
\textcolor{darkblue}{Attribute} \footnotesize \setstretch{1}

Formal sind Matrizen atomare Vektoren mit einem \texttt{dim} Attribut

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{A }\OtherTok{=} \FunctionTok{matrix}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{12}\NormalTok{, }\AttributeTok{nrow =} \DecValTok{4}\NormalTok{ )              }\CommentTok{\#  4 x 3 Matrix}
\FunctionTok{attributes}\NormalTok{(A)                            }\CommentTok{\# Aufrufen der Attribute von A}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
> $dim
> [1] 4 3
\end{verbatim}

\texttt{rownames()} und \texttt{colnames()} spezifizieren das Attribut
\texttt{dimnames}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{rownames}\NormalTok{(A) }\OtherTok{=} \FunctionTok{c}\NormalTok{(}\StringTok{"P1"}\NormalTok{,}\StringTok{"P2"}\NormalTok{,}\StringTok{"P3"}\NormalTok{,}\StringTok{"P4"}\NormalTok{)     }\CommentTok{\# Benennung der Zeilen von A}
\FunctionTok{colnames}\NormalTok{(A) }\OtherTok{=} \FunctionTok{c}\NormalTok{(}\StringTok{"Age"}\NormalTok{, }\StringTok{"Hgt"}\NormalTok{, }\StringTok{"Wgt"}\NormalTok{)     }\CommentTok{\# Benennung der Spalten von A}
\NormalTok{A                                        }\CommentTok{\# A mit Attribut dimnames}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
>    Age Hgt Wgt
> P1   1   5   9
> P2   2   6  10
> P3   3   7  11
> P4   4   8  12
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{attr}\NormalTok{(A, }\StringTok{"dimnames"}\NormalTok{)                      }\CommentTok{\# Aufrufen des Attributs dimnames}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
> [[1]]
> [1] "P1" "P2" "P3" "P4"
> 
> [[2]]
> [1] "Age" "Hgt" "Wgt"
\end{verbatim}

Bei Matrizen ist die Benennung von Zeilen und Spalten eher ungewöhnlich.
\end{frame}

\begin{frame}{}
\protect\hypertarget{section-5}{}
\setstretch{3}
\vfill
\large

Matrizen

\textbf{Übungen und Selbstkontrollfragen} \vfill
\end{frame}

\begin{frame}{Übungen und Selbstkontrollfragen}
\protect\hypertarget{uxfcbungen-und-selbstkontrollfragen}{}
\small
\setstretch{1.8}

\begin{enumerate}
\tightlist
\item
  Dokumentieren Sie alle in dieser Einheit eingeführten Befehle in einem
  R Skript.
\item
  Erzeugen Sie in R die Matrizen \begin{equation*}
  A = 
  \begin{pmatrix}
  4 & 3 & 2 & 1 \\
  3 & 2 & 1 & 4 \\
  2 & 1 & 4 & 3
  \end{pmatrix}
  \mbox{ und }
  B = 
  \begin{pmatrix}
  1 & 0 & 1 & 0 \\
  0 & 1 & 0 & 1 \\
  1 & 0 & 1 & 0
  \end{pmatrix}
  \end{equation*}
\item
  Kopieren Sie die zweite Zeile von \(A\) in einen Vektor.
\item
  Kopieren Sie die erste und dritte Spalte von \(B\) in eine 3
  \(\times\) 2 Matrix
\item
  Setzen Sie alle Nullen in \(B\) auf -1.
\item
  Setzen Sie die zweite Zeile von \(A\) auf \((1\,2\,3\,4)\).
\item
  Addieren Sie die Matrizen \(A\) und \(B\).
\item
  Multiplizieren Matrix \(A\) mit 3.
\item
  Konkatenieren Sie die Matrizen \(A\) und \(B\) zeilenweise.
\item
  Konkatenieren Sie die Matrizen \(A\) und \(B\) spaltenweise.
\end{enumerate}
\end{frame}

\end{document}
