Introduction to Generalized Linear Models (GLMs) – Data types & distributions
1 Lecture
2 Exercise 1
Explore the shape of the Probability Mass Function (PMF) of the the Poisson distribution by recreating the figure below from the Wikipedia article on the Poisson distribution.
Of course, you do not have to reproduce every specific feature of the figure, e.g. colours, axis labels, plotting characters, but the general structure with 3 distributions in one figure should be similar.
Make sure you understand how to interpret the PMFs!
When you look at your final figure, think about the following question: How does the variance of the distribution change with the mean?
To generate values of the Poisson PMF you need the function dpois()
The exercise can be approached with the following steps:
- Generate three tables with the probability mass functions (PMFs) for each value of \(\lambda\)
- Combine the three tables into a single large one (see !(Day 3 - Creating vector and tables)[https://ecomods.github.io/r-statistics-course/slides/Day3/session_vectors_tables.html])
- Create a plot from the large table using
aes(..., colors = lambda)
- In your final table the column
lambda(or similar name) should be a factor to get nice colours in the final figure. - You can convert it by
r my_data$lambda <- as.factor(my_data$lambda)
3 Exercise 2
Explore the shape of the PMF of the Binomial distribution by creating two figures
- Showing three PMFs with varying p but constant N
- With three PMFs with varying N but constant P
Again, think about the following question: How does the variance of the distribution change with its mean?
- To generate values of the Binomial PMF you need the function
dbinom() - In this function the argument
sizeis the same as N = no. of trials and the argumentprobis the same as p = success probability in a single trial.
Look at the tips for exercise 1 :o)