Metric Predicted Variable With One Nominal Predictor Variable

Size: px
Start display at page:

Download "Metric Predicted Variable With One Nominal Predictor Variable"

Transcription

1 Metric Predicted Variable With One Nominal Predictor Variable Tim Frasier Copyright Tim Frasier This work is licensed under the Creative Commons Attribution 4.0 International license. Click here for more information.

2 Goals & General Idea

3 Goals When would we use this type of analysis? When we want to know the effect of being in a group on some metric predictor variable Very common type of data set Monetary income (metric) and political party (nominal) Drug effect across groups etc. Frequently analyzed with a single factor (or one-way) ANOVA

4 General Idea Trying to quantify the relationship between two different sets of data One (y) is the metric response (or predicted) variable The other (x) is the nominal predictor variable that represents the categories in which measurements, samples, individuals can belong

5 Equation or Kruschke (2015) p. 555

6 Equation or Mean value of y, across all groupings Kruschke (2015) p. 555

7 Equation or Degree to which values are deflected above or below mean value, based on being in group j Kruschke (2015) p. 555

8 Equation or βj = 0, by definition Will add this constraint to our model Kruschke (2015) p. 555

9 The Data

10 Data Suppose you re studying a horse population that had a large die-off in one year (from which you ve obtained samples) You re interested in the effect of inbreeding on survival in this population May expect the following patterns

11 Data Age Class Adults Juveniles Foals Prediction & Logic Lowest degree of inbreeding (have survived previous selection events; inbred individuals have already been weeded out ) Moderate degree of inbreeding (have survived some, but not too many, previous selection events; some inbred individuals have been weeded out ) Highest degree of inbreeding (have not had to survive any previous selection events; no inbred individuals have been weeded out yet, except in this event)

12 Data Metric predicted variable with one nominal predictor Inbreeding Coefficient Age Class 0.12 adult 0.23 juvenile 0.06 adult 0.22 foal 0.34 foal 0.17 juvenile

13 Getting A Feel for the Data Before we can create an appropriate model, we need to get a feel for the data I think two main plots would be useful here A box plot grouped by age class Points grouped by age class

14 Getting A Feel for the Data Put simhorsedata.csv file in R s working directory Load it into R horsedata <- read.table( simhorsedata.csv, header = TRUE, sep =, )

15 Getting A Feel for the Data Make a box plot Make the aclass field a factor aclass <- factor(horsedata$aclass, levels = c( adult, juvenile, foal ), ordered = TRUE)

16 Getting A Feel for the Data Make a box plot Make the aclass field a factor aclass <- factor(horsedata$aclass, levels = c( adult, juvenile, foal ), ordered = TRUE) Note that we re specifying the order here, so that adult will be 1, juvenile will be 2, and foal will be 3. Otherwise, these would be ordered alphabetically (i.e., adult, foal, juvenile)

17 Getting A Feel for the Data Make the boxplot boxplot(horsedata$ic ~ aclass, ylab = Inbreeding Coefficient, xlab = Age Class, col = skyblue ) Inbreeding Coefficient adult juvenile foal Age Class

18 Getting A Feel for the Data Can also plot the points to see raw data (requires a few tricks) plot(as.numeric(aclass), horsedata$ic, xaxt = n, ylab = Inbreeding Coefficient, xlab = Age Class, pch = 16, col = rgb(0, 0, 0, 0.25)) axis(1, at = c(1, 2, 3), labels = c( adult, juvenile, foal ))

19 Getting A Feel for the Data Can also plot the points to see raw data (requires a few tricks) plot(as.numeric(aclass), horsedata$ic, xaxt = n, ylab = Inbreeding Coefficient, xlab = Age Class, pch = 16, col = rgb(0, 0, 0, 0.25)) axis(1, at = c(1, 2, 3), labels = c( adult, juvenile, foal )) Have to use numeric form, otherwise it defaults to a box plot.

20 Getting A Feel for the Data Can also plot the points to see raw data (requires a few tricks) plot(as.numeric(aclass), horsedata$ic, xaxt = n, ylab = Inbreeding Coefficient, xlab = Age Class, pch = 16, col = rgb(0, 0, 0, 0.25)) axis(1, at = c(1, 2, 3), labels = c( adult, juvenile, foal )) Tell R not to plot the x-axis labels (we ll add our own later). These would be numbers.

21 Getting A Feel for the Data Can also plot the points to see raw data (requires a few tricks) plot(as.numeric(aclass), horsedata$ic, xaxt = n, ylab = Inbreeding Coefficient, xlab = Age Class, pch = 16, col = rgb(0, 0, 0, 0.25)) axis(1, at = c(1, 2, 3), labels = c( adult, juvenile, foal )) Make points filled black circles that are opaque, so that you can see where there is overlap.

22 Getting A Feel for the Data Can also plot the points to see raw data (requires a few tricks) plot(as.numeric(aclass), horsedata$ic, xaxt = n, ylab = Inbreeding Coefficient, xlab = Age Class, pch = 16, col = rgb(0, 0, 0, 0.25)) axis(1, at = c(1, 2, 3), labels = c( adult, juvenile, foal )) Function for adding a custom axis.

23 Getting A Feel for the Data Can also plot the points to see raw data (requires a few tricks) plot(as.numeric(aclass), horsedata$ic, xaxt = n, ylab = Inbreeding Coefficient, xlab = Age Class, pch = 16, col = rgb(0, 0, 0, 0.25)) axis(1, at = c(1, 2, 3), labels = c( adult, juvenile, foal )) Position of the axis. 1 = bottom, 2 = left, 3 = top, 4 = right.

24 Getting A Feel for the Data Can also plot the points to see raw data (requires a few tricks) plot(as.numeric(aclass), horsedata$ic, xaxt = n, ylab = Inbreeding Coefficient, xlab = Age Class, pch = 16, col = rgb(0, 0, 1, 0.25)) axis(1, at = c(1, 2, 3), labels = c( adult, juvenile, foal )) At what positions to add our custom labels (remember that as numeric, our categories are 1, 2, and 3)

25 Getting A Feel for the Data Can also plot the points to see raw data (requires a few tricks) plot(as.numeric(aclass), horsedata$ic, xaxt = n, ylab = Inbreeding Coefficient, xlab = Age Class, pch = 16, col = rgb(0, 0, 0, 0.25)) axis(1, at = c(1, 2, 3), labels = c( adult, juvenile, foal )) What the labels should be at our indicated positions.

26 Getting A Feel for the Data Inbreeding Coefficient adult juvenile foal Age Class

27 Getting A Feel for the Data This is a little too clumped to be useful Can jitter the x-values of the points to make it clearer This adds random noise to the data in the specified axis plot(jitter(as.numeric(aclass)), horsedata$ic, xaxt = n, ylab = Inbreeding Coefficient, xlab = Age Class, pch = 16, col = rgb(0, 0, 1, 0.5)) axis(1, at = c(1, 2, 3), labels = c( adult, juvenile, foal ))

28 Getting A Feel for the Data Inbreeding Coefficient adult juvenile foal Age Class

29 Frequentist Approach

30 Frequentist Approach Again, these type of data are typically analyzed with an ANOVA, which can be called with the aov function anovatest <- aov(horsedata$ic ~ horsedata$aclass)

31 Frequentist Approach Can get the coefficient estimates by looking at the model tables print(model.tables(anovatest)) Tables of effects horsedata$aclass adult foal juvenile rep

32 Frequentist Approach Can get the coefficient estimates by looking at the model tables print(model.tables(anovatest)) Tables of effects horsedata$aclass adult foal juvenile rep Adults have lower inbreeding coefficients than the population average, those of juveniles are slightly lower than average, and those for foals are substantially above average.

33 Frequentist Approach Can get the coefficient estimates by looking at the model tables print(model.tables(anovatest)) Tables of effects horsedata$aclass adult foal juvenile rep Number of subjects in each category.

34 Frequentist Approach Can get the coefficient estimates by looking at the model tables print(model.tables(anovatest)) Tables of effects horsedata$aclass adult foal juvenile rep Note lack of confidence intervals in coefficient estimates.

35 Frequentist Approach Can see if this effect is significant summary(anovatest) Df Sum Sq Mean Sq F value Pr(>F) horsedata$aclass <2e-16 *** Residuals Signif. codes: 0 *** ** 0.01 * Yep.

36 Bayesian Approach

37 Load Libraries & Functions library(runjags) library(coda) source( plotpost.r )

38 Prepare the Data Standardize metric (y) data y <- horsedata$ic ymean <- mean(y) ysd <- sd(y) zy <- (y - ymean) / ysd N <- length(y)

39 Prepare the Data Organize the nominal (x) data x <- as.numeric(horsedata$aclass) xnames <- levels(as.factor(horsedata$aclass)) nageclass <- length(unique(horsedata$aclass))

40 Prepare the Data Organize the nominal (x) data x <- as.numeric(horsedata$aclass) xnames <- levels(as.factor(horsedata$aclass)) nageclass <- length(unique(horsedata$aclass)) Save the nominal data as x in numeric form (1, 2, and 3 instead of adult, foal, and juvenile )

41 Prepare the Data Organize the nominal (x) data x <- as.numeric(horsedata$aclass) xnames <- levels(as.factor(horsedata$aclass)) nageclass <- length(unique(horsedata$aclass)) Make a vector ( xnames ) with the names of each nominal category. xnames is now adult, foal, juvenile.

42 Prepare the Data Organize the nominal (x) data x <- as.numeric(horsedata$aclass) xnames <- levels(as.factor(horsedata$aclass)) nageclass <- length(unique(horsedata$aclass)) Get the number of categories in the data set (unique values in our nominal data set)

43 Define the Model

44 Define the Model µ τ = 1/σ 2 - norm yi

45 Define the Model α gamma β µ τ = 1/σ 2 - norm yi

46 Define the Model 0 10 µ τ = 1/σ 2 - norm α gamma β µ τ = 1/σ 2 - norm yi

47 Define the Model µ τ = 1/σ 2 µ τ = 1/σ 2 - norm - norm α gamma β µ τ = 1/σ 2 - norm yi

48 Define the Model µ τ = 1/σ 2 µ τ = 1/σ 2 norm norm - Same as before, data just coded differently!!! 1.1 (Will have some differences in actual model) α β gamma µ τ = 1/σ 2 norm yi

49 Define the Model modelstring = " model { #--- Likelihood ---# for (i in 1:N) { y[i] ~ dnorm(mu[i], tau) mu[i] <- a0 + a1[x[i]] } #--- Priors ---# a0 ~ dnorm(0, 1/10^2) for (j in 1:nAgeClass) { a1[j] ~ dnorm(0, 1/10^2) } sigma ~ dgamma(1.1, 0.11) tau <- 1 / sigma^2... (there s more)

50 Define the Model modelstring = " model { How to indicate that value of x[i] is categorical, rather than a number to be taken at face value #--- Likelihood ---# for (i in 1:N) { y[i] ~ dnorm(mu[i], tau) mu[i] <- a0 + a1[x[i]] } #--- Priors ---# a0 ~ dnorm(0, 1/10^2) for (j in 1:nAgeClass) { a1[j] ~ dnorm(0, 1/10^2) } sigma ~ dgamma(1.1, 0.11) tau <- 1 / sigma^2... (there s more)

51 Define the Model modelstring = " model { Using a instead of standard b (for beta) to indicate that these coefficients are not yet standardized to sum to zero #--- Likelihood ---# for (i in 1:N) { y[i] ~ dnorm(mu[i], tau) mu[i] <- a0 + a1[x[i]] } #--- Priors ---# a0 ~ dnorm(0, 1/10^2) for (j in 1:nAgeClass) { a1[j] ~ dnorm(0, 1/10^2) } sigma ~ dgamma(1.1, 0.11) tau <- 1 / sigma^2... (there s more)

52 Define the Model... # # # Convert a0 and a1[] to sum-to-zero b0 and b1[] # # # #--- Create matrix with values for each age class---# for (j in 1:nAgeClass) { m[j] <- a0 + a1[j] } #--- Make b0 the mean across all age classes ---# b0 <- mean(m[1:nageclass] #--- Make b1[j] the difference between that category and b0 ---# for (j in 1:nAgeClass) { b1[j] <- m[j] - b0 } } writelines(modelstring, con = model.txt )

53 Prepare Data for JAGS Specify as a list for JAGS datalist = list ( y = zy, x = x, N = N, nageclass = nageclass )

54 Specify Initial Values initslist <- function() { list( sigma = rgamma(n = 1, shape = 1.1, rate = 0.11), a0 = rnorm(n = 1, mean = 0, sd = 10), a1 = rnorm(n = nageclass, mean = 0, sd = 10) ) }

55 Specify Initial Values initslist <- function() { list( sigma = rgamma(n = 1, shape = 1.1, rate = 0.11), a0 = rnorm(n = 1, mean = 0, sd = 10), a1 = rnorm(n = nageclass, mean = 0, sd = 10) ) } Note that we need one for each category!

56 Specify MCMC Parameters and Run library(runjags) runjagsout <- run.jags( method = simple, model = model.txt, monitor = c( b0, b1, sigma ), data = datalist, inits = initslist, n.chains = 3, adapt = 500, burnin = 1000, sample = 20000, thin = 1, summarise = TRUE, plots = FALSE)

57 Specify MCMC Parameters and Run library(runjags) runjagsout <- run.jags( method = simple, model = model.txt, monitor = c( b0, b1, sigma ), data = datalist, inits = initslist, n.chains = 3, adapt = 500, burnin = 1000, sample = 20000, thin = 1, summarise = TRUE, plots = FALSE) Will keep track of all b1 values (one for each category)

58 Evaluate Performance of the Model

59 Testing Model Performance Retrieve the data and take a peak at the structure codasamples = as.mcmc.list(runjagsout) head(codasamples[[1]]) Markov Chain Monte Carlo (MCMC) output: Start = 1501 End = 1507 Thinning interval = 1 b0 b1[1] b1[2] b1[3] sigma

60 Testing Model Performance Trace plots par(mfrow = c(2,3)) traceplot(codasamples)

61 Testing Model Performance Autocorrelation plots autocorr.plot(codasamples[[1]]) b0 b1[1] Autocorrelation Autocorrelation Lag Lag b1[2] b1[3] Autocorrelation Autocorrelation Lag Lag sigma Autocorrelation Lag

62 Testing Model Performance Gelman & Rubin diagnostic gelman.diag(codasamples) Potential scale reduction factors: Point est. Upper C.I. b0 1 1 b1[1] 1 1 b1[2] 1 1 b1[3] 1 1 sigma 1 1 Multivariate psrf 1

63 Testing Model Performance Effective size effectivesize(codasamples) b0 b1[1] b1[2] b1[3] sigma

64 Viewing Results

65 Parsing Data Convert codasamples to a matrix Will concatenate chains into one long one mcmcchain = as.matrix(codasamples)

66 Parsing Data Separate out data for each parameter #--- sigma---# zsigma = mcmcchain[, sigma ] #--- b0---# zb0 = mcmcchain[, b0 ] #--- b1---# chainlength = length(zb0) zb1 = matrix(0, ncol = chainlength, nrow = nageclass) for (j in 1:nAgeClass) { zb1[j, ] = mcmcchain[, paste("b1[", j, "]", sep = "")] }

67 Parsing Data Separate out data for each parameter Create a matrix to hold posteriors for each category in our Age Class variable: #--- sigma---# zsigma = mcmcchain[, sigma ] One column for each step in the chain, One row per category #--- b0---# zb0 = mcmcchain[, b0 ] #--- b1---# chainlength = length(zb0) zb1 = matrix(0, ncol = chainlength, nrow = nageclass) for (j in 1:nAgeClass) { zb1[j, ] = mcmcchain[, paste("b1[", j, "]", sep = "")] }

68 Parsing Data Separate out data for each parameter #--- sigma---# zsigma = mcmcchain[, sigma ] #--- b0---# zb0 = mcmcchain[, b0 ] Fill each row (category) with the posteriors from the appropriately-named column from the mcmcchain #--- b1---# chainlength = length(zb0) zb1 = matrix(0, ncol = chainlength, nrow = nageclass) for (j in 1:nAgeClass) { zb1[j, ] = mcmcchain[, paste("b1[", j, "]", sep = "")] }

69 Parsing Data Separate out data for each parameter #--- sigma---# zsigma = mcmcchain[, sigma ] #--- b0---# zb0 = mcmcchain[, b0 ] Will be: b1[1] b1[2] b1[3] #--- b1---# chainlength = length(zb0) zb1 = matrix(0, ncol = chainlength, nrow = nageclass) for (j in 1:nAgeClass) { zb1[j, ] = mcmcchain[, paste("b1[", j, "]", sep = "")] }

70 Convert Back to Original Scale #--- sigma---# sigma <- zsigma * ysd #--- b0---# b0 <- zb0 * ysd + ymean #--- b1---# b1 = matrix(0, ncol = chainlength, nrow = nageclass) for (j in 1:nAgeClass) { b1[j, ] = zb1[j, ] * ysd }

71 Plot Posterior Distributions Sigma par(mfrow = c(1, 1)) histinfo = plotpost(sigma, xlab = bquote(sigma)) mean = % HDI σ

72 Plot Posterior Distributions b0 histinfo = plotpost(b0, xlab = bquote(beta[0])) mean = % HDI β 0

73 Plot Posterior Distributions b1 par(mfrow = c(1, 3)) for (j in 1:nAgeClass) { histinfo = plotpost(b1[j, ], xlab = bquote(b1[.(j)]), main = paste( b1:, xnames[j])) }

74 Plot Posterior Distributions b1 Remember, these are effects of being in each category (deflections) To get actual values, add b0 to each b1: adult b1: foal b1: juvenile mean = mean = mean = % HDI % HDI % HDI b b b1 3

75 Comparing Groups

76 Comparing Groups eadults <- b1[1, ] efoals <- b1[2, ] ejuveniles <- b1[3, ]

77 Comparing Groups eadults <- b1[1, ] efoals <- b1[2, ] ejuveniles <- b1[3, ] e to indicate we are looking at effects rather than actual values

78 Comparing Groups Adult vs foal par(mfrow = c(1, 1)) AvF <- eadults - efoals histinfo = plotpost(avf, main = "Adult v Foal", xlab = "") Adult v Foal mean = % HDI

79 Comparing Groups Adult vs juvenile AvJ <- eadults - ejuveniles histinfo = plotpost(avj, main = "Adult v Juvenile", xlab = "") Adult v Juvenile mean = % HDI

80 Comparing Groups Foal vs juvenile FvJ <- efoals - ejuveniles histinfo = plotpost(fvj, main = "Foal v Juvenile", xlab = "") Foal v Juvenile mean = % HDI

81 Comparing Groups Adult vs others JpF <- (ejuveniles + efoals) / 2 AvO <- eadults - JpF histinfo = plotpost(avo, main = "Adults v Others", xlab = "") Adults v Others mean = % HDI

82 Comparing Groups Foals vs others ApJ <- (eadults + ejuveniles) / 2 FvO <- efoals - ApJ histinfo = plotpost(fvo, main = "Foals v Others", xlab = "") Foals v Others mean = % HDI

83 Comparing Groups Dot charts Nice for comparing the same parameter across groups Need to make a new data frame containing the mean, and error bars for the parameter in each group

84 Comparing Groups Dot charts First, store the mean of each coefficient as a new vector b1means <- c(mean(eadults), mean(efoals), mean(ejuveniles))

85 Comparing Groups Dot charts Get the highest density interval for each beta, and combine source( HDIofMCMC.R ) b1.adultshdi <- HDIofMCMC(eAdults) b1.foalshdi <- HDIofMCMC(eFoals) b1.juvenileshdi <- HDIofMCMC(eJuveniles) b1hdi <- rbind(b1.adultshdi, b1.foalshdi, b1.juvenileshdi)

86 Comparing Groups Dot charts Get the highest density interval for each beta, and combine source( HDIofMCMC.R ) b1.adultshdi <- HDIofMCMC(eAdults) b1.foalshdi <- HDIofMCMC(eFoals) b1.juvenileshdi <- HDIofMCMC(eJuveniles) b1hdi <- rbind(b1.adultshdi, b1.foalshdi, b1.juvenileshdi) Returns the upper and lower values

87 Comparing Groups Dot charts Get the highest density interval for each beta, and combine source( HDIofMCMC.R ) b1.adultshdi <- HDIofMCMC(eAdults) b1.foalshdi <- HDIofMCMC(eFoals) b1.juvenileshdi <- HDIofMCMC(eJuveniles) b1hdi <- rbind(b1.adultshdi, b1.foalshdi, b1.juvenileshdi) Can change what percentage to use with the credmass argument (i.e., to get the 89% HDI, credmass = 0.89)

88 Comparing Groups Dot charts Get the highest density interval for each beta, and combine source( HDIofMCMC.R ) b1.adultshdi <- HDIofMCMC(eAdults) b1.foalshdi <- HDIofMCMC(eFoals) b1.juvenileshdi <- HDIofMCMC(eJuveniles) b1hdi <- rbind(b1.adultshdi, b1.foalshdi, b1.juvenileshdi)

89 Comparing Groups Dot charts Plot the means of each group dotchart(b1means, pch = 16, labels = c("adult", "foal", juvenile"), xlim = c(min(b1hdi), max(b1hdi)), xlab = "Beta coefficient") juvenile foal adult Beta coefficients

90 Comparing Groups Dot charts Add the HDI bars segments(b1hdi[, 1], 1:3, b1hdi[, 2], 1:3, lwd = 2) juvenile foal adult Beta coefficients

91 Comparing Groups Dot charts Add the HDI bars segments(b1hdi[, 1], 1:3, b1hdi[, 2], 1:3, lwd = 2) juvenile x- and foal y-coordinates of starting positions for line adult segments Beta coefficients

92 Comparing Groups Dot charts Add the HDI bars segments(b1hdi[, 1], 1:3, b1hdi[, 2], 1:3, lwd = 2) juvenile x- and foal y-coordinates of ending positions for line adult segments Beta coefficients

93 Comparing Groups Dot charts Add the HDI bars segments(b1hdi[, 1], 1:3, b1hdi[, 2], 1:3, lwd = 2) juvenile foal Make line twice as thick as default adult Beta coefficients

94 Comparing Groups Dot charts Add the HDI bars segments(b1hdi[, 1], 1:3, b1hdi[, 2], 1:3, lwd = 2) juvenile foal adult Beta coefficients

95 Check Validity of Model: Posterior Predictive Check

96 Posterior Predictive Check Generate new y values for a subset of x values in the data set based on estimates for coefficients Compare these predicted y values to the real ones

97 Posterior Predictive Check Select a subset of the data on which to make predictions (let s pick 50) newrows <- seq(from = 1, to = NROW(horsedata), length = 50)

98 Posterior Predictive Check Select a subset of the data on which to make predictions (let s pick 30) npred <- 30 newrows <- seq(from = 1, to = NROW(horsedata), length = npred) newrows [1] [10] [19] [28] [37] [46]

99 Posterior Predictive Check newrows <- round(newrows) newrows [1] [27]

100 Posterior Predictive Check Parse out these data from the original data frame newdata <- horsedata[newrows, ]

101 Posterior Predictive Check Order based on categorical (predictor) variable to make plots clearer later newdata <- newdata[order(newdata$aclass), ]

102 Posterior Predictive Check Separate out just the x data too, on which we will make predictions xnew <- newdata$aclass xnewnums <- as.numeric(xnew)

103 Posterior Predictive Check Organize categorical coefficients into one data frame (makes indexing later easier) b <- rbind(eadults, efoals, ejuveniles)

104 Posterior Predictive Check Next, define a matrix that will hold all of the predicted y values Number of rows is the number of x values for prediction Number of columns is the number of y values generated from the MCMC process We ll start with the matrix filled with zeros, but will fill it in later postsampsize = length(b1) ynew = matrix(0, nrow = length(xnew), ncol = postsampsize)

105 Posterior Predictive Check Define a matrix for holding the HDI limits of the predicted y values Same number of rows as above Only two columns (one for each end of the HDI) yhdilim = matrix(0, nrow = length(xnew), ncol = 2)

106 Posterior Predictive Check Now, populate the ynew matrix by generating one predicted y value for each step in the chain for (i in 1:postSampSize) { ynew[, i] <- rnorm(length(xnew), mean = b0 + b[xnewnums], sd = sigma) }

107 Posterior Predictive Check Now, populate the ynew matrix by generating one predicted y value for each step in the chain for (i in 1:postSampSize) { ynew[, i] <- rnorm(length(xnew), mean = b0 + b[xnewnums], sd = sigma) } For every step in the chain, fill out a new column (all rows) of the new matrix...

108 Posterior Predictive Check Now, populate the ynew matrix by generating one predicted y value for each step in the chain for (i in 1:postSampSize) { ynew[, i] <- rnorm(length(xnew), mean = b0 + b[xnewnums], sd = sigma) }...pulling the same number of x values as in our xnew list from a normal distribution...

109 Posterior Predictive Check Now, populate the ynew matrix by generating one predicted y value for each step in the chain for (i in 1:postSampSize) { ynew[, i] <- rnorm(length(xnew), mean = b0 + b[xnewnums], sd = sigma) }...with a mean based on b0 plus which category each x value is in...

110 Posterior Predictive Check Now, populate the ynew matrix by generating one predicted y value for each step in the chain for (i in 1:postSampSize) { ynew[, i] <- rnorm(length(xnew), mean = b0 + b[xnewnums], sd = sigma) }...and a standard deviation based on those data from the posterior.

111 Posterior Predictive Check Calculate means for each prediction, and the associated low and high 95% HDI estimates means <- rowmeans(ynew) source("hdiofmcmc.r") for (i in 1:length(xNew)) { yhdilim[i, ] <- HDIofMCMC(yNew[i, ]) }

112 Posterior Predictive Check Combine the data predtable <- cbind(xnew, means, yhdilim)

113 Posterior Predictive Check Plot the results #--- Plot the predicted values (dot plot) ---# dotchart(means, labels = 1:nPred, xlim = c(min(yhdilim), max(yhdilim)), xlab = "Inbreeding Coefficient", pch = 16) segments(yhdilim[, 1], 1:nPred, yhdilim[, 2], 1:nPred, lwd = 2) #--- Plot the true values ---# points(x = newdata$ic, y = 1:nPred, pch = 16, col = rgb(1, 0, 0, 0.5))

114 Posterior Predictive Check Inbreeding Coefficient

115 Questions?

116 Homework!

117 Homework Current model assumes equal standard deviation (precision) for each category Modify the model to estimate a different standard deviation for each category, and evaluate in the same ways as we did the mean

118 Creative Commons License Anyone is allowed to distribute, remix, tweak, and build upon this work, even commercially, as long as they credit me for the original creation. See the Creative Commons website for more information. Click here to go back to beginning

Hierarchical Modeling

Hierarchical Modeling Hierarchical Modeling Tim Frasier Copyright Tim Frasier This work is licensed under the Creative Commons Attribution 4.0 International license. Click here for more information. General Idea One benefit

More information

Metric Predicted Variable on Two Groups

Metric Predicted Variable on Two Groups Metric Predicted Variable on Two Groups Tim Frasier Copyright Tim Frasier This work is licensed under the Creative Commons Attribution 4.0 International license. Click here for more information. Goals

More information

Metric Predicted Variable on One Group

Metric Predicted Variable on One Group Metric Predicted Variable on One Group Tim Frasier Copyright Tim Frasier This work is licensed under the Creative Commons Attribution 4.0 International license. Click here for more information. Prior Homework

More information

Multiple Regression: Nominal Predictors. Tim Frasier

Multiple Regression: Nominal Predictors. Tim Frasier Multiple Regression: Nominal Predictors Tim Frasier Copyright Tim Frasier This work is licensed under the Creative Commons Attribution 4.0 International license. Click here for more information. Goals

More information

Multiple Regression: Mixed Predictor Types. Tim Frasier

Multiple Regression: Mixed Predictor Types. Tim Frasier Multiple Regression: Mixed Predictor Types Tim Frasier Copyright Tim Frasier This work is licensed under the Creative Commons Attribution 4.0 International license. Click here for more information. The

More information

Count Predicted Variable & Contingency Tables

Count Predicted Variable & Contingency Tables Count Predicted Variable & Contingency Tables Tim Frasier Copyright Tim Frasier This work is licensed under the Creative Commons Attribution 4.0 International license. Click here for more information.

More information

Introduction to R, Part I

Introduction to R, Part I Introduction to R, Part I Basic math, variables, and variable types Tim Frasier Copyright Tim Frasier This work is licensed under the Creative Commons Attribution 4.0 International license. Click here

More information

Bayesian Statistics: An Introduction

Bayesian Statistics: An Introduction : An Introduction Tim Frasier Copyright Tim Frasier This work is licensed under the Creative Commons Attribution 4.0 International license. Click here for more information. Outline 1. Bayesian statistics,

More information

R Demonstration ANCOVA

R Demonstration ANCOVA R Demonstration ANCOVA Objective: The purpose of this week s session is to demonstrate how to perform an analysis of covariance (ANCOVA) in R, and how to plot the regression lines for each level of the

More information

36-463/663Multilevel and Hierarchical Models

36-463/663Multilevel and Hierarchical Models 36-463/663Multilevel and Hierarchical Models From Bayes to MCMC to MLMs Brian Junker 132E Baker Hall brian@stat.cmu.edu 1 Outline Bayesian Statistics and MCMC Distribution of Skill Mastery in a Population

More information

WinBUGS : part 2. Bruno Boulanger Jonathan Jaeger Astrid Jullion Philippe Lambert. Gabriele, living with rheumatoid arthritis

WinBUGS : part 2. Bruno Boulanger Jonathan Jaeger Astrid Jullion Philippe Lambert. Gabriele, living with rheumatoid arthritis WinBUGS : part 2 Bruno Boulanger Jonathan Jaeger Astrid Jullion Philippe Lambert Gabriele, living with rheumatoid arthritis Agenda 2! Hierarchical model: linear regression example! R2WinBUGS Linear Regression

More information

Why Bayesian approaches? The average height of a rare plant

Why Bayesian approaches? The average height of a rare plant Why Bayesian approaches? The average height of a rare plant Estimation and comparison of averages is an important step in many ecological analyses and demographic models. In this demonstration you will

More information

36-463/663: Multilevel & Hierarchical Models HW09 Solution

36-463/663: Multilevel & Hierarchical Models HW09 Solution 36-463/663: Multilevel & Hierarchical Models HW09 Solution November 15, 2016 Quesion 1 Following the derivation given in class, when { n( x µ) 2 L(µ) exp, f(p) exp 2σ 2 0 ( the posterior is also normally

More information

BUGS Bayesian inference Using Gibbs Sampling

BUGS Bayesian inference Using Gibbs Sampling BUGS Bayesian inference Using Gibbs Sampling Glen DePalma Department of Statistics May 30, 2013 www.stat.purdue.edu/~gdepalma 1 / 20 Bayesian Philosophy I [Pearl] turned Bayesian in 1971, as soon as I

More information

Univariate Descriptive Statistics for One Sample

Univariate Descriptive Statistics for One Sample Department of Psychology and Human Development Vanderbilt University 1 Introduction 2 3 4 5 6 7 8 Introduction Our first step in descriptive statistics is to characterize the data in a single group of

More information

STAT Lecture 11: Bayesian Regression

STAT Lecture 11: Bayesian Regression STAT 491 - Lecture 11: Bayesian Regression Generalized Linear Models Generalized linear models (GLMs) are a class of techniques that include linear regression, logistic regression, and Poisson regression.

More information

Leslie matrices and Markov chains.

Leslie matrices and Markov chains. Leslie matrices and Markov chains. Example. Suppose a certain species of insect can be divided into 2 classes, eggs and adults. 10% of eggs survive for 1 week to become adults, each adult yields an average

More information

Markov Chain Monte Carlo

Markov Chain Monte Carlo Markov Chain Monte Carlo Recall: To compute the expectation E ( h(y ) ) we use the approximation E(h(Y )) 1 n n h(y ) t=1 with Y (1),..., Y (n) h(y). Thus our aim is to sample Y (1),..., Y (n) from f(y).

More information

MALA versus Random Walk Metropolis Dootika Vats June 4, 2017

MALA versus Random Walk Metropolis Dootika Vats June 4, 2017 MALA versus Random Walk Metropolis Dootika Vats June 4, 2017 Introduction My research thus far has predominantly been on output analysis for Markov chain Monte Carlo. The examples on which I have implemented

More information

Package leiv. R topics documented: February 20, Version Type Package

Package leiv. R topics documented: February 20, Version Type Package Version 2.0-7 Type Package Package leiv February 20, 2015 Title Bivariate Linear Errors-In-Variables Estimation Date 2015-01-11 Maintainer David Leonard Depends R (>= 2.9.0)

More information

Class 04 - Statistical Inference

Class 04 - Statistical Inference Class 4 - Statistical Inference Question 1: 1. What parameters control the shape of the normal distribution? Make some histograms of different normal distributions, in each, alter the parameter values

More information

Bayesian Networks in Educational Assessment

Bayesian Networks in Educational Assessment Bayesian Networks in Educational Assessment Estimating Parameters with MCMC Bayesian Inference: Expanding Our Context Roy Levy Arizona State University Roy.Levy@asu.edu 2017 Roy Levy MCMC 1 MCMC 2 Posterior

More information

Prediction problems 3: Validation and Model Checking

Prediction problems 3: Validation and Model Checking Prediction problems 3: Validation and Model Checking Data Science 101 Team May 17, 2018 Outline Validation Why is it important How should we do it? Model checking Checking whether your model is a good

More information

Linear Regression. Data Model. β, σ 2. Process Model. ,V β. ,s 2. s 1. Parameter Model

Linear Regression. Data Model. β, σ 2. Process Model. ,V β. ,s 2. s 1. Parameter Model Regression: Part II Linear Regression y~n X, 2 X Y Data Model β, σ 2 Process Model Β 0,V β s 1,s 2 Parameter Model Assumptions of Linear Model Homoskedasticity No error in X variables Error in Y variables

More information

A Parameter Expansion Approach to Bayesian SEM Estimation

A Parameter Expansion Approach to Bayesian SEM Estimation A Parameter Expansion Approach to Bayesian SEM Estimation Ed Merkle and Yves Rosseel Utrecht University 24 June 2016 Yves Rosseel A Parameter Expansion Approach to Bayesian SEM Estimation 1 / 51 overview

More information

Lecture 9: Predictive Inference for the Simple Linear Model

Lecture 9: Predictive Inference for the Simple Linear Model See updates and corrections at http://www.stat.cmu.edu/~cshalizi/mreg/ Lecture 9: Predictive Inference for the Simple Linear Model 36-401, Fall 2015, Section B 29 September 2015 Contents 1 Confidence intervals

More information

Statistical Simulation An Introduction

Statistical Simulation An Introduction James H. Steiger Department of Psychology and Human Development Vanderbilt University Regression Modeling, 2009 Simulation Through Bootstrapping Introduction 1 Introduction When We Don t Need Simulation

More information

Metropolis-Hastings Algorithm

Metropolis-Hastings Algorithm Strength of the Gibbs sampler Metropolis-Hastings Algorithm Easy algorithm to think about. Exploits the factorization properties of the joint probability distribution. No difficult choices to be made to

More information

Trevor Davies, Dalhousie University, Halifax, Canada Steven J.D. Martell, International Pacific Halibut Commission, Seattle WA.

Trevor Davies, Dalhousie University, Halifax, Canada Steven J.D. Martell, International Pacific Halibut Commission, Seattle WA. Comparison of ADMB-RE and JAGS Bayesian State-space length disaggregated population model: Estimating total mortality by decade for winter skate (Leucoraja ocellata) Trevor Davies, Dalhousie University,

More information

Stat 5031 Quadratic Response Surface Methods (QRSM) Sanford Weisberg November 30, 2015

Stat 5031 Quadratic Response Surface Methods (QRSM) Sanford Weisberg November 30, 2015 Stat 5031 Quadratic Response Surface Methods (QRSM) Sanford Weisberg November 30, 2015 One Variable x = spacing of plants (either 4, 8 12 or 16 inches), and y = plant yield (bushels per acre). Each condition

More information

Matematisk statistik allmän kurs, MASA01:A, HT-15 Laborationer

Matematisk statistik allmän kurs, MASA01:A, HT-15 Laborationer Lunds universitet Matematikcentrum Matematisk statistik Matematisk statistik allmän kurs, MASA01:A, HT-15 Laborationer General information on labs During the rst half of the course MASA01 we will have

More information

SAS Syntax and Output for Data Manipulation:

SAS Syntax and Output for Data Manipulation: CLP 944 Example 5 page 1 Practice with Fixed and Random Effects of Time in Modeling Within-Person Change The models for this example come from Hoffman (2015) chapter 5. We will be examining the extent

More information

Bayesian Regression Linear and Logistic Regression

Bayesian Regression Linear and Logistic Regression When we want more than point estimates Bayesian Regression Linear and Logistic Regression Nicole Beckage Ordinary Least Squares Regression and Lasso Regression return only point estimates But what if we

More information

Homework 6 Solutions

Homework 6 Solutions Homework 6 Solutions set.seed(1) library(mvtnorm) samp.theta

More information

Chapter 5 Exercises 1

Chapter 5 Exercises 1 Chapter 5 Exercises 1 Data Analysis & Graphics Using R, 2 nd edn Solutions to Exercises (December 13, 2006) Preliminaries > library(daag) Exercise 2 For each of the data sets elastic1 and elastic2, determine

More information

Measurement, Scaling, and Dimensional Analysis Summer 2017 METRIC MDS IN R

Measurement, Scaling, and Dimensional Analysis Summer 2017 METRIC MDS IN R Measurement, Scaling, and Dimensional Analysis Summer 2017 Bill Jacoby METRIC MDS IN R This handout shows the contents of an R session that carries out a metric multidimensional scaling analysis of the

More information

FAV i R This paper is produced mechanically as part of FAViR. See for more information.

FAV i R This paper is produced mechanically as part of FAViR. See  for more information. Bayesian Claim Severity Part 2 Mixed Exponentials with Trend, Censoring, and Truncation By Benedict Escoto FAV i R This paper is produced mechanically as part of FAViR. See http://www.favir.net for more

More information

Simple, Marginal, and Interaction Effects in General Linear Models

Simple, Marginal, and Interaction Effects in General Linear Models Simple, Marginal, and Interaction Effects in General Linear Models PRE 905: Multivariate Analysis Lecture 3 Today s Class Centering and Coding Predictors Interpreting Parameters in the Model for the Means

More information

The evdbayes Package

The evdbayes Package The evdbayes Package April 19, 2006 Version 1.0-5 Date 2006-18-04 Title Bayesian Analysis in Extreme Theory Author Alec Stephenson and Mathieu Ribatet. Maintainer Mathieu Ribatet

More information

Lecture 9: Predictive Inference

Lecture 9: Predictive Inference Lecture 9: Predictive Inference There are (at least) three levels at which we can make predictions with a regression model: we can give a single best guess about what Y will be when X = x, a point prediction;

More information

The lmm Package. May 9, Description Some improved procedures for linear mixed models

The lmm Package. May 9, Description Some improved procedures for linear mixed models The lmm Package May 9, 2005 Version 0.3-4 Date 2005-5-9 Title Linear mixed models Author Original by Joseph L. Schafer . Maintainer Jing hua Zhao Description Some improved

More information

22s:152 Applied Linear Regression. Take random samples from each of m populations.

22s:152 Applied Linear Regression. Take random samples from each of m populations. 22s:152 Applied Linear Regression Chapter 8: ANOVA NOTE: We will meet in the lab on Monday October 10. One-way ANOVA Focuses on testing for differences among group means. Take random samples from each

More information

Using R in 200D Luke Sonnet

Using R in 200D Luke Sonnet Using R in 200D Luke Sonnet Contents Working with data frames 1 Working with variables........................................... 1 Analyzing data............................................... 3 Random

More information

Bayesian Inference on Joint Mixture Models for Survival-Longitudinal Data with Multiple Features. Yangxin Huang

Bayesian Inference on Joint Mixture Models for Survival-Longitudinal Data with Multiple Features. Yangxin Huang Bayesian Inference on Joint Mixture Models for Survival-Longitudinal Data with Multiple Features Yangxin Huang Department of Epidemiology and Biostatistics, COPH, USF, Tampa, FL yhuang@health.usf.edu January

More information

Weakness of Beta priors (or conjugate priors in general) They can only represent a limited range of prior beliefs. For example... There are no bimodal beta distributions (except when the modes are at 0

More information

DAG models and Markov Chain Monte Carlo methods a short overview

DAG models and Markov Chain Monte Carlo methods a short overview DAG models and Markov Chain Monte Carlo methods a short overview Søren Højsgaard Institute of Genetics and Biotechnology University of Aarhus August 18, 2008 Printed: August 18, 2008 File: DAGMC-Lecture.tex

More information

Correlation. January 11, 2018

Correlation. January 11, 2018 Correlation January 11, 2018 Contents Correlations The Scattterplot The Pearson correlation The computational raw-score formula Survey data Fun facts about r Sensitivity to outliers Spearman rank-order

More information

22s:152 Applied Linear Regression. There are a couple commonly used models for a one-way ANOVA with m groups. Chapter 8: ANOVA

22s:152 Applied Linear Regression. There are a couple commonly used models for a one-way ANOVA with m groups. Chapter 8: ANOVA 22s:152 Applied Linear Regression Chapter 8: ANOVA NOTE: We will meet in the lab on Monday October 10. One-way ANOVA Focuses on testing for differences among group means. Take random samples from each

More information

Diagnostics and Transformations Part 2

Diagnostics and Transformations Part 2 Diagnostics and Transformations Part 2 Bivariate Linear Regression James H. Steiger Department of Psychology and Human Development Vanderbilt University Multilevel Regression Modeling, 2009 Diagnostics

More information

Lab 3 A Quick Introduction to Multiple Linear Regression Psychology The Multiple Linear Regression Model

Lab 3 A Quick Introduction to Multiple Linear Regression Psychology The Multiple Linear Regression Model Lab 3 A Quick Introduction to Multiple Linear Regression Psychology 310 Instructions.Work through the lab, saving the output as you go. You will be submitting your assignment as an R Markdown document.

More information

Bayesian Graphical Models

Bayesian Graphical Models Graphical Models and Inference, Lecture 16, Michaelmas Term 2009 December 4, 2009 Parameter θ, data X = x, likelihood L(θ x) p(x θ). Express knowledge about θ through prior distribution π on θ. Inference

More information

ST 740: Markov Chain Monte Carlo

ST 740: Markov Chain Monte Carlo ST 740: Markov Chain Monte Carlo Alyson Wilson Department of Statistics North Carolina State University October 14, 2012 A. Wilson (NCSU Stsatistics) MCMC October 14, 2012 1 / 20 Convergence Diagnostics:

More information

Markov Chain Monte Carlo methods

Markov Chain Monte Carlo methods Markov Chain Monte Carlo methods By Oleg Makhnin 1 Introduction a b c M = d e f g h i 0 f(x)dx 1.1 Motivation 1.1.1 Just here Supresses numbering 1.1.2 After this 1.2 Literature 2 Method 2.1 New math As

More information

Introductory Statistics with R: Linear models for continuous response (Chapters 6, 7, and 11)

Introductory Statistics with R: Linear models for continuous response (Chapters 6, 7, and 11) Introductory Statistics with R: Linear models for continuous response (Chapters 6, 7, and 11) Statistical Packages STAT 1301 / 2300, Fall 2014 Sungkyu Jung Department of Statistics University of Pittsburgh

More information

Introduction to the Analysis of Hierarchical and Longitudinal Data

Introduction to the Analysis of Hierarchical and Longitudinal Data Introduction to the Analysis of Hierarchical and Longitudinal Data Georges Monette, York University with Ye Sun SPIDA June 7, 2004 1 Graphical overview of selected concepts Nature of hierarchical models

More information

STK 2100 Oblig 1. Zhou Siyu. February 15, 2017

STK 2100 Oblig 1. Zhou Siyu. February 15, 2017 STK 200 Oblig Zhou Siyu February 5, 207 Question a) Make a scatter box plot for the data set. Answer:Here is the code I used to plot the scatter box in R. library ( MASS ) 2 pairs ( Boston ) Figure : Scatter

More information

Bayesian inference for a population growth model of the chytrid fungus Philipp H Boersch-Supan, Sadie J Ryan, and Leah R Johnson September 2016

Bayesian inference for a population growth model of the chytrid fungus Philipp H Boersch-Supan, Sadie J Ryan, and Leah R Johnson September 2016 Bayesian inference for a population growth model of the chytrid fungus Philipp H Boersch-Supan, Sadie J Ryan, and Leah R Johnson September 2016 1 Preliminaries This vignette illustrates the steps needed

More information

Gov 2000: 7. What is Regression?

Gov 2000: 7. What is Regression? Gov 2000: 7. What is Regression? Matthew Blackwell Harvard University mblackwell@gov.harvard.edu October 15, 2016 Where are we? Where are we going? What we ve been up to: estimating parameters of population

More information

Finite Mixture Model Diagnostics Using Resampling Methods

Finite Mixture Model Diagnostics Using Resampling Methods Finite Mixture Model Diagnostics Using Resampling Methods Bettina Grün Johannes Kepler Universität Linz Friedrich Leisch Universität für Bodenkultur Wien Abstract This paper illustrates the implementation

More information

Chapter 4 Exercises 1. Data Analysis & Graphics Using R Solutions to Exercises (December 11, 2006)

Chapter 4 Exercises 1. Data Analysis & Graphics Using R Solutions to Exercises (December 11, 2006) Chapter 4 Exercises 1 Data Analysis & Graphics Using R Solutions to Exercises (December 11, 2006) Preliminaries > library(daag) Exercise 2 Draw graphs that show, for degrees of freedom between 1 and 100,

More information

Package bpp. December 13, 2016

Package bpp. December 13, 2016 Type Package Package bpp December 13, 2016 Title Computations Around Bayesian Predictive Power Version 1.0.0 Date 2016-12-13 Author Kaspar Rufibach, Paul Jordan, Markus Abt Maintainer Kaspar Rufibach Depends

More information

Bayesian Estimation An Informal Introduction

Bayesian Estimation An Informal Introduction Mary Parker, Bayesian Estimation An Informal Introduction page 1 of 8 Bayesian Estimation An Informal Introduction Example: I take a coin out of my pocket and I want to estimate the probability of heads

More information

Bayesian Inference for Regression Parameters

Bayesian Inference for Regression Parameters Bayesian Inference for Regression Parameters 1 Bayesian inference for simple linear regression parameters follows the usual pattern for all Bayesian analyses: 1. Form a prior distribution over all unknown

More information

Stat 5303 (Oehlert): Balanced Incomplete Block Designs 1

Stat 5303 (Oehlert): Balanced Incomplete Block Designs 1 Stat 5303 (Oehlert): Balanced Incomplete Block Designs 1 > library(stat5303libs);library(cfcdae);library(lme4) > weardata

More information

Generalized Linear Models

Generalized Linear Models Generalized Linear Models Assumptions of Linear Model Homoskedasticity Model variance No error in X variables Errors in variables No missing data Missing data model Normally distributed error Error in

More information

Business Statistics. Lecture 9: Simple Regression

Business Statistics. Lecture 9: Simple Regression Business Statistics Lecture 9: Simple Regression 1 On to Model Building! Up to now, class was about descriptive and inferential statistics Numerical and graphical summaries of data Confidence intervals

More information

Inference Tutorial 2

Inference Tutorial 2 Inference Tutorial 2 This sheet covers the basics of linear modelling in R, as well as bootstrapping, and the frequentist notion of a confidence interval. When working in R, always create a file containing

More information

Robust Bayesian Regression

Robust Bayesian Regression Readings: Hoff Chapter 9, West JRSSB 1984, Fúquene, Pérez & Pericchi 2015 Duke University November 17, 2016 Body Fat Data: Intervals w/ All Data Response % Body Fat and Predictor Waist Circumference 95%

More information

Introduction to Statistics and R

Introduction to Statistics and R Introduction to Statistics and R Mayo-Illinois Computational Genomics Workshop (2018) Ruoqing Zhu, Ph.D. Department of Statistics, UIUC rqzhu@illinois.edu June 18, 2018 Abstract This document is a supplimentary

More information

Statistics Lab One-way Within-Subject ANOVA

Statistics Lab One-way Within-Subject ANOVA Statistics Lab One-way Within-Subject ANOVA PSYCH 710 9 One-way Within-Subjects ANOVA Section 9.1 reviews the basic commands you need to perform a one-way, within-subject ANOVA and to evaluate a linear

More information

WinLTA USER S GUIDE for Data Augmentation

WinLTA USER S GUIDE for Data Augmentation USER S GUIDE for Version 1.0 (for WinLTA Version 3.0) Linda M. Collins Stephanie T. Lanza Joseph L. Schafer The Methodology Center The Pennsylvania State University May 2002 Dev elopment of this program

More information

Markov Chain Monte Carlo

Markov Chain Monte Carlo Markov Chain Monte Carlo Jamie Monogan University of Georgia Spring 2013 For more information, including R programs, properties of Markov chains, and Metropolis-Hastings, please see: http://monogan.myweb.uga.edu/teaching/statcomp/mcmc.pdf

More information

610 - R1A "Make friends" with your data Psychology 610, University of Wisconsin-Madison

610 - R1A Make friends with your data Psychology 610, University of Wisconsin-Madison 610 - R1A "Make friends" with your data Psychology 610, University of Wisconsin-Madison Prof Colleen F. Moore Note: The metaphor of making friends with your data was used by Tukey in some of his writings.

More information

Package lmm. R topics documented: March 19, Version 0.4. Date Title Linear mixed models. Author Joseph L. Schafer

Package lmm. R topics documented: March 19, Version 0.4. Date Title Linear mixed models. Author Joseph L. Schafer Package lmm March 19, 2012 Version 0.4 Date 2012-3-19 Title Linear mixed models Author Joseph L. Schafer Maintainer Jing hua Zhao Depends R (>= 2.0.0) Description Some

More information

Statistics in Environmental Research (BUC Workshop Series) II Problem sheet - WinBUGS - SOLUTIONS

Statistics in Environmental Research (BUC Workshop Series) II Problem sheet - WinBUGS - SOLUTIONS Statistics in Environmental Research (BUC Workshop Series) II Problem sheet - WinBUGS - SOLUTIONS 1. (a) The posterior mean estimate of α is 14.27, and the posterior mean for the standard deviation of

More information

Bayesian Regression for a Dirichlet Distributed Response using Stan

Bayesian Regression for a Dirichlet Distributed Response using Stan Bayesian Regression for a Dirichlet Distributed Response using Stan Holger Sennhenn-Reulen 1 1 Department of Growth and Yield, Northwest German Forest Research Institute, Göttingen, Germany arxiv:1808.06399v1

More information

Introduction to Bayesian Statistics and Markov Chain Monte Carlo Estimation. EPSY 905: Multivariate Analysis Spring 2016 Lecture #10: April 6, 2016

Introduction to Bayesian Statistics and Markov Chain Monte Carlo Estimation. EPSY 905: Multivariate Analysis Spring 2016 Lecture #10: April 6, 2016 Introduction to Bayesian Statistics and Markov Chain Monte Carlo Estimation EPSY 905: Multivariate Analysis Spring 2016 Lecture #10: April 6, 2016 EPSY 905: Intro to Bayesian and MCMC Today s Class An

More information

Package msir. R topics documented: April 7, Type Package Version Date Title Model-Based Sliced Inverse Regression

Package msir. R topics documented: April 7, Type Package Version Date Title Model-Based Sliced Inverse Regression Type Package Version 1.3.1 Date 2016-04-07 Title Model-Based Sliced Inverse Regression Package April 7, 2016 An R package for dimension reduction based on finite Gaussian mixture modeling of inverse regression.

More information

Kernel density estimation in R

Kernel density estimation in R Kernel density estimation in R Kernel density estimation can be done in R using the density() function in R. The default is a Guassian kernel, but others are possible also. It uses it s own algorithm to

More information

Markov Chain Monte Carlo (MCMC) and Model Evaluation. August 15, 2017

Markov Chain Monte Carlo (MCMC) and Model Evaluation. August 15, 2017 Markov Chain Monte Carlo (MCMC) and Model Evaluation August 15, 2017 Frequentist Linking Frequentist and Bayesian Statistics How can we estimate model parameters and what does it imply? Want to find the

More information

Simple, Marginal, and Interaction Effects in General Linear Models: Part 1

Simple, Marginal, and Interaction Effects in General Linear Models: Part 1 Simple, Marginal, and Interaction Effects in General Linear Models: Part 1 PSYC 943 (930): Fundamentals of Multivariate Modeling Lecture 2: August 24, 2012 PSYC 943: Lecture 2 Today s Class Centering and

More information

Designing Information Devices and Systems I Fall 2018 Lecture Notes Note Positioning Sytems: Trilateration and Correlation

Designing Information Devices and Systems I Fall 2018 Lecture Notes Note Positioning Sytems: Trilateration and Correlation EECS 6A Designing Information Devices and Systems I Fall 08 Lecture Notes Note. Positioning Sytems: Trilateration and Correlation In this note, we ll introduce two concepts that are critical in our positioning

More information

Statistical Computing Session 4: Random Simulation

Statistical Computing Session 4: Random Simulation Statistical Computing Session 4: Random Simulation Paul Eilers & Dimitris Rizopoulos Department of Biostatistics, Erasmus University Medical Center p.eilers@erasmusmc.nl Masters Track Statistical Sciences,

More information

A Handbook of Statistical Analyses Using R 2nd Edition. Brian S. Everitt and Torsten Hothorn

A Handbook of Statistical Analyses Using R 2nd Edition. Brian S. Everitt and Torsten Hothorn A Handbook of Statistical Analyses Using R 2nd Edition Brian S. Everitt and Torsten Hothorn CHAPTER 12 Analysing Longitudinal Data I: Computerised Delivery of Cognitive Behavioural Therapy Beat the Blues

More information

Advanced Statistical Modelling

Advanced Statistical Modelling Markov chain Monte Carlo (MCMC) Methods and Their Applications in Bayesian Statistics School of Technology and Business Studies/Statistics Dalarna University Borlänge, Sweden. Feb. 05, 2014. Outlines 1

More information

Package bayeslm. R topics documented: June 18, Type Package

Package bayeslm. R topics documented: June 18, Type Package Type Package Package bayeslm June 18, 2018 Title Efficient Sampling for Gaussian Linear Regression with Arbitrary Priors Version 0.8.0 Date 2018-6-17 Author P. Richard Hahn, Jingyu He, Hedibert Lopes Maintainer

More information

From Practical Data Analysis with JMP, Second Edition. Full book available for purchase here. About This Book... xiii About The Author...

From Practical Data Analysis with JMP, Second Edition. Full book available for purchase here. About This Book... xiii About The Author... From Practical Data Analysis with JMP, Second Edition. Full book available for purchase here. Contents About This Book... xiii About The Author... xxiii Chapter 1 Getting Started: Data Analysis with JMP...

More information

A Handbook of Statistical Analyses Using R 2nd Edition. Brian S. Everitt and Torsten Hothorn

A Handbook of Statistical Analyses Using R 2nd Edition. Brian S. Everitt and Torsten Hothorn A Handbook of Statistical Analyses Using R 2nd Edition Brian S. Everitt and Torsten Hothorn CHAPTER 12 Analysing Longitudinal Data I: Computerised Delivery of Cognitive Behavioural Therapy Beat the Blues

More information

Detection ASTR ASTR509 Jasper Wall Fall term. William Sealey Gosset

Detection ASTR ASTR509 Jasper Wall Fall term. William Sealey Gosset ASTR509-14 Detection William Sealey Gosset 1876-1937 Best known for his Student s t-test, devised for handling small samples for quality control in brewing. To many in the statistical world "Student" was

More information

Stat 5101 Lecture Notes

Stat 5101 Lecture Notes Stat 5101 Lecture Notes Charles J. Geyer Copyright 1998, 1999, 2000, 2001 by Charles J. Geyer May 7, 2001 ii Stat 5101 (Geyer) Course Notes Contents 1 Random Variables and Change of Variables 1 1.1 Random

More information

Community Health Needs Assessment through Spatial Regression Modeling

Community Health Needs Assessment through Spatial Regression Modeling Community Health Needs Assessment through Spatial Regression Modeling Glen D. Johnson, PhD CUNY School of Public Health glen.johnson@lehman.cuny.edu Objectives: Assess community needs with respect to particular

More information

Univariate analysis. Simple and Multiple Regression. Univariate analysis. Simple Regression How best to summarise the data?

Univariate analysis. Simple and Multiple Regression. Univariate analysis. Simple Regression How best to summarise the data? Univariate analysis Example - linear regression equation: y = ax + c Least squares criteria ( yobs ycalc ) = yobs ( ax + c) = minimum Simple and + = xa xc xy xa + nc = y Solve for a and c Univariate analysis

More information

Information. Hierarchical Models - Statistical Methods. References. Outline

Information. Hierarchical Models - Statistical Methods. References. Outline Information Hierarchical Models - Statistical Methods Sarah Filippi 1 University of Oxford Hilary Term 2015 Webpage: http://www.stats.ox.ac.uk/~filippi/msc_ hierarchicalmodels_2015.html Lectures: Week

More information

Gov 2000: 9. Regression with Two Independent Variables

Gov 2000: 9. Regression with Two Independent Variables Gov 2000: 9. Regression with Two Independent Variables Matthew Blackwell Harvard University mblackwell@gov.harvard.edu Where are we? Where are we going? Last week: we learned about how to calculate a simple

More information

Online Appendix to Mixed Modeling for Irregularly Sampled and Correlated Functional Data: Speech Science Spplications

Online Appendix to Mixed Modeling for Irregularly Sampled and Correlated Functional Data: Speech Science Spplications Online Appendix to Mixed Modeling for Irregularly Sampled and Correlated Functional Data: Speech Science Spplications Marianne Pouplier, Jona Cederbaum, Philip Hoole, Stefania Marin, Sonja Greven R Syntax

More information

Using SPSS for One Way Analysis of Variance

Using SPSS for One Way Analysis of Variance Using SPSS for One Way Analysis of Variance This tutorial will show you how to use SPSS version 12 to perform a one-way, between- subjects analysis of variance and related post-hoc tests. This tutorial

More information

ASA Section on Survey Research Methods

ASA Section on Survey Research Methods REGRESSION-BASED STATISTICAL MATCHING: RECENT DEVELOPMENTS Chris Moriarity, Fritz Scheuren Chris Moriarity, U.S. Government Accountability Office, 411 G Street NW, Washington, DC 20548 KEY WORDS: data

More information

1 Introduction 1. 2 The Multiple Regression Model 1

1 Introduction 1. 2 The Multiple Regression Model 1 Multiple Linear Regression Contents 1 Introduction 1 2 The Multiple Regression Model 1 3 Setting Up a Multiple Regression Model 2 3.1 Introduction.............................. 2 3.2 Significance Tests

More information

Addition to PGLR Chap 6

Addition to PGLR Chap 6 Arizona State University From the SelectedWorks of Joseph M Hilbe August 27, 216 Addition to PGLR Chap 6 Joseph M Hilbe, Arizona State University Available at: https://works.bepress.com/joseph_hilbe/69/

More information

Generalized Linear Models

Generalized Linear Models Generalized Linear Models Assumptions of Linear Model Homoskedasticity Model variance No error in X variables Errors in variables No missing data Missing data model Normally distributed error GLM Error

More information