Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Exercises
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Simulation
ExEv
Exercises
Commits
11111792
Commit
11111792
authored
2 years ago
by
Marc Sommerhalder
Browse files
Options
Downloads
Patches
Plain Diff
Update solutions
parent
74223413
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Musterloesungen/08_Diskrete_Verteilungen_Musterloesungen_R.ipynb
+29
-4
29 additions, 4 deletions
...oesungen/08_Diskrete_Verteilungen_Musterloesungen_R.ipynb
with
29 additions
and
4 deletions
Musterloesungen/08_Diskrete_Verteilungen_Musterloesungen_R.ipynb
+
29
−
4
View file @
11111792
...
...
@@ -562,13 +562,38 @@
"sum(dist[1 <= dist$k & dist$k <= 3,]$p)"
]
},
{
"cell_type": "markdown",
"id": "c4d34af2",
"metadata": {},
"source": [
"## Übung 10. Empirische Verteilung"
]
},
{
"cell_type": "code",
"execution_count":
null
,
"id": "
bd0f4343
",
"execution_count":
5
,
"id": "
98c2f256
",
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1] 5.48\n"
]
}
],
"source": [
"x <- c(\n",
" 5, 6, 8, 10, 1, 2, 9, 10, 3, 4, 9, 5, 3, 9, 3, 5, 7,\n",
" 6, 1, 1, 9, 8, 9, 6, 9, 4, 5, 8, 2, 4, 2, 5, 10, 2,\n",
" 4, 5, 10, 3, 6, 3, 1, 8, 1, 3, 5, 5, 2, 10, 8, 10\n",
")\n",
"histogram <- hist(x, breaks=0.5:10.5, plot=FALSE)\n",
"E <- sum(histogram$mids * histogram$density)\n",
"print(E)"
]
}
],
"metadata": {
...
...
%% Cell type:markdown id:06419e14 tags:
# 8 - Diskrete Verteilungen
%% Cell type:markdown id:4b055420 tags:
## Übung 2. Empirische Verteilung
%% Cell type:code id:23ede07d tags:
```
R
x
<-
c
(
1
,
4
,
2
,
2
,
4
,
3
,
1
,
2
,
2
,
2
,
3
,
4
,
5
,
1
,
1
,
2
,
3
,
4
,
5
,
5
)
histogram
<-
hist
(
x
,
breaks
=
0.5
:
5.5
,
probability
=
TRUE
)
histogram
$
counts
<-
cumsum
(
histogram
$
counts
)
histogram
$
counts
<-
histogram
$
counts
/
max
(
histogram
$
counts
)
plot
(
histogram
)
```
%% Output
%% Cell type:code id:f9cf4327 tags:
```
R
histogram
<-
hist
(
x
,
breaks
=
0.5
:
5.5
,
plot
=
FALSE
)
E
<-
sum
(
histogram
$
mids
*
histogram
$
density
)
S
<-
sum
(
histogram
$
mids
^
2
*
histogram
$
density
)
-
E
^
2
print
(
c
(
E
,
S
))
```
%% Output
[1] 2.80 1.86
%% Cell type:markdown id:3e18a91f tags:
## Übung 5. Binomialverteilung
%% Cell type:code id:55ce6ecd tags:
```
R
dbinom
(
0
,
10
,
0.05
)
```
%% Output
0.598736939238379
0.598736939238379
%% Cell type:code id:15a4c19c tags:
```
R
dbinom
(
1
,
10
,
0.05
)
```
%% Output
0.315124704862305
0.315124704862305
%% Cell type:code id:4202c5f8 tags:
```
R
dbinom
(
2
,
10
,
0.05
)
```
%% Output
0.0746347985200195
0.0746347985200195
%% Cell type:code id:0f4191b2 tags:
```
R
1
-
pbinom
(
2
,
10
,
0.05
)
```
%% Output
0.0115035573792969
0.0115035573792969
%% Cell type:markdown id:97c95e85 tags:
## Übung 6. Poissonverteilung
%% Cell type:code id:10a26cd1 tags:
```
R
dpois
(
3
,
5
)
```
%% Output
0.140373895814281
0.140373895814281
%% Cell type:code id:93ac0221 tags:
```
R
1
-
ppois
(
9
,
5
)
```
%% Output
0.0318280573062049
0.0318280573062049
%% Cell type:code id:5018483c tags:
```
R
padd
<-
function
(
a
,
b
)
{
a
+
b
-
a
*
b
}
padd
(
1
-
ppois
(
9
,
5
),
1
-
ppois
(
7
,
4
))
```
%% Output
0.081334189445324
0.081334189445324
%% Cell type:code id:fe96ddab tags:
```
R
1
-
ppois
(
16
,
9
)
```
%% Output
0.0111059093775838
0.0111059093775838
%% Cell type:markdown id:43a530b0 tags:
## Übung 7. Hypergeometrische Verteilung
%% Cell type:code id:4f8102b9 tags:
```
R
k
<-
0
:
6
p
<-
sapply
(
k
,
function
(
x
)
dhyper
(
x
,
6
,
42
-
6
,
6
))
dist
<-
data.frame
(
k
,
p
)
dist
```
%% Output
A data.frame: 7 × 2
| k <int> | p <dbl> |
|---|---|
| 0 | 3.713060e-01 |
| 1 | 4.311941e-01 |
| 2 | 1.684352e-01 |
| 3 | 2.722185e-02 |
| 4 | 1.801446e-03 |
| 5 | 4.117591e-05 |
| 6 | 1.906292e-07 |
A data.frame: 7 × 2
\begin{tabular}{ll}
k & p\\
<int> & <dbl>\\
\hline
0 & 3.713060e-01\\
1 & 4.311941e-01\\
2 & 1.684352e-01\\
3 & 2.722185e-02\\
4 & 1.801446e-03\\
5 & 4.117591e-05\\
6 & 1.906292e-07\\
\end{tabular}
%% Cell type:code id:90922910 tags:
```
R
1
-
phyper
(
2
,
6
,
42
-
6
,
6
)
sum
(
dist
[
3
<=
dist
$
k
&
dist
$
k
<=
6
,]
$
p
)
```
%% Output
0.0290646625691555
0.0290646625691555
0.0290646625691555
0.0290646625691555
%% Cell type:code id:522939ab tags:
```
R
phyper
(
5
,
6
,
42
-
6
,
6
)
sum
(
dist
[
0
<=
dist
$
k
&
dist
$
k
<=
5
,]
$
p
)
```
%% Output
0.999999809370798
0.999999809370798
0.999999809370797
0.999999809370797
%% Cell type:code id:3c04e5b7 tags:
```
R
phyper
(
4
,
6
,
42
-
6
,
6
)
-
phyper
(
0
,
6
,
42
-
6
,
6
)
sum
(
dist
[
1
<=
dist
$
k
&
dist
$
k
<=
3
,]
$
p
)
```
%% Output
0.628652598485718
0.628652598485718
0.626851152525093
0.626851152525093
%% Cell type:code id:bd0f4343 tags:
%% Cell type:markdown id:c4d34af2 tags:
## Übung 10. Empirische Verteilung
%% Cell type:code id:98c2f256 tags:
```
R
x
<-
c
(
5
,
6
,
8
,
10
,
1
,
2
,
9
,
10
,
3
,
4
,
9
,
5
,
3
,
9
,
3
,
5
,
7
,
6
,
1
,
1
,
9
,
8
,
9
,
6
,
9
,
4
,
5
,
8
,
2
,
4
,
2
,
5
,
10
,
2
,
4
,
5
,
10
,
3
,
6
,
3
,
1
,
8
,
1
,
3
,
5
,
5
,
2
,
10
,
8
,
10
)
histogram
<-
hist
(
x
,
breaks
=
0.5
:
10.5
,
plot
=
FALSE
)
E
<-
sum
(
histogram
$
mids
*
histogram
$
density
)
print
(
E
)
```
%% Output
[1] 5.48
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment