# Load the real data used in the publication by Mueller (Vogelwarte, 2021)
# Counts of known pairs in the country 1990-2020
y <- c(0,2,7,5,1,2,4,8,10,11,16,11,10,13,19,31,
20,26,19,21,34,35,43,53,66,61,72,120,102,159,199)
year <- 1990:2020 # Define year range
x <- (year-1989) # Scaled, but not centered year as a covariate
x <- x-16 # Now it's centered
oldpar <- par(no.readonly = TRUE)
par(mfrow = c(1, 2), mar = c(5,5,5,2), cex.lab = 1.5, cex.axis = 1.5, cex.main = 1.5)
plot(table(y), xlab = 'Count (y)', ylab = 'Frequency', frame = FALSE,
type = 'h', lend = 'butt', lwd = 5, col = 'gray20', main = 'Frequency distribution of counts')
plot(year, y, xlab = 'Year (x)', ylab = 'Count (y)', frame = FALSE, cex = 1.5,
pch = 16, col = 'gray20', main = 'Relationship y ~ x')
fm <- glm(y ~ x, family = 'poisson') # Add Poisson GLM line of best fit
lines(year, predict(fm, type = 'response'), lwd = 3, col = 'red', lty = 3)
# \donttest{
# Execute the function with default function args
# In a real test you should run more iterations
par(mfrow = c(1,1))
str(tmp <- demoMCMC(niter=100, nburn=50))
# Use data created above
par(mfrow = c(1,1))
str(tmp <- demoMCMC(y = y, x = x, niter=100, nburn=50))
# }
par(oldpar)
Run the code above in your browser using DataLab