We use the following packages:

library(mice)
library(dplyr)
library(magrittr)
library(DAAG)

The following table shows numbers of occasions when inhibition (i.e., no flow of current across a membrane) occurred within 120 s, for different concentrations of the protein peptide-C. The outcome yes implies that inhibition has occurred.

conc 0.1 0.5  1 10 20 30 50 70 80 100 150 
no     7   1 10  9  2  9 13  1  1   4   3 
yes    0   0  3  4  0  6  7  0  0   1   7

  1. Create this data in R

  1. Add two new variables (columns) to the data

  1. Fit the logistic model with margin as the weights

  1. Look at the summary of the fitted object

  1. Inspect the plots number 1 and 5 for fit

  1. conc is somewhat skewed. Run the model again with a log-transformation for conc.

  1. Look at the summary of the fitted object again

  1. Inspects the plots number 1 and 5 of the fitted object based on log(conc).

  1. The moths data frame in the DAAG package contains data from a study of the effect of habitat on the densities of two species of moth (A and P). The quasipoisson distribution is a reasonable model for these data. Try modeling the variable A using this distribution. Is there a better link function than the standard?

  1. Let’s try to specify our own link function: \(f(x) = \log(\exp(x)-1)\). Generate data like this:
n <- 1000                       
x <- runif(n)
sh <- 2                        
y <- rgamma(n,scale=log(2+3*x)/sh,shape=sh)

Specify the link function and run a glm regressing y on x. Hint: Look at the help file for family. You need to make an object of type “link-glm”, containing the items needed for glm to run: a link function, an inverse link, the derivative of the inverse link, and a function that describes the domain of the inverse link.


End of Practical