Solution Anti-fungal treatment (R software)

Size: px
Start display at page:

Download "Solution Anti-fungal treatment (R software)"

Transcription

1 Contents Solution Anti-fungal treatment (R software) Question 1: Data import 2 Question 2: Compliance with the timetable 4 Question 3: population average model 5 Question 4: continuous time model 9 Question 5: conditional odds ratios 11 Question 6: glmer model 12 Question 7: with a random slope 14 Appendix A: Graphical display 16 Question

2 First, load the necessary packages library(lme4) library(geepack) library(doby) # esticon library(lattice) Question 1: Data import df.onych <- read.table(" + header = TRUE, na.strings = ".") Re-order the levels of the qualitative variables: names(df.onych) <- gsub(pattern = "response", replacement = "response.", + x = names(df.onych), fixed = TRUE) names(df.onych) <- gsub(pattern = "time", replacement = "time.", + x = names(df.onych), fixed = TRUE) df.onych$treatment <- factor(df.onych$treatment, levels = 0:1, + labels = c("200mg", "250mg")) df.onych$id <- factor(df.onych$id) Reshape the dataset: varying_columns <- c(paste0("response.",1:7), paste0("time.",1:7)) dfl.onych <- reshape(df.onych, + varying = which(names(df.onych) %in% varying_columns), + sep = ".", idvar = c(" id"), v.names = c("symptoms","time"), + direction = "long", timevar = "visitnb") dfl.onych$visitnb.factor <- factor(dfl.onych$visitnb, + levels = 1:7, labels = paste0("visit",1:7)) dfl.onych$timeweeks.planned <- factor(dfl.onych$visitnb, + levels = 1:7, + labels = c(0,4,8,12,24,36,48)) dfl.onych$timeweeks.planned <- as.numeric(as.character(dfl.onych$timeweeks.planned)) dfl.onych$timeweeks <- dfl.onych$time*52/12 2

3 Compute the prevalence: aggregate(symptoms ~ visitnb + treatment, + data = dfl.onych, + FUN = function(x){ + c(n = length(x), sum = sum(x), mean = mean(x), variance = var(x)) + } + ) visitnb treatment symptoms.n symptoms.sum symptoms.mean symptoms.variance mg mg mg mg mg mg mg mg mg mg mg mg mg mg

4 Question 2: Compliance with the timetable aggregate(timeweeks ~ timeweeks.planned + treatment, + data = dfl.onych, + FUN = function(x){ + c(median = median(x), min = min(x), max = max(x)) + } + ) timeweeks.planned treatment timeweeks.median timeweeks.min timeweeks.max mg mg mg mg mg mg mg mg mg mg mg mg mg mg # see appendix A for a graphical display 4

5 Question 3: population average model Baseline adjustement: dfl.onych$treatment_adj <- dfl.onych$treatment dfl.onych$treatment_adj[dfl.onych$visitnb.factor=="visit1"] <- "200mg" dfl.onych$treatadj_x_visit <- paste(dfl.onych$visitnb.factor, + dfl.onych$treatment_adj, sep =" ") table(dfl.onych$visitnb.factor,dfl.onych$treatment_adj) 200mg 250mg visit visit visit visit visit visit visit #### NOTE: remember to reorder by id otherwise gee do not fit correctly dfl.onych <- dfl.onych[order(dfl.onych$id),] Estimate the model gee.binun <- geeglm(symptoms ~ treatadj_x_visit -1, + id = id, data = dfl.onych, + family = binomial(link = "logit"), corstr = "unstructured") summary(gee.binun)$coefficient Estimate Std.err Wald Pr( W ) treatadj_x_visitvisit1 200mg e-06 treatadj_x_visitvisit2 200mg e-06 treatadj_x_visitvisit2 250mg e-07 treatadj_x_visitvisit3 200mg e-07 treatadj_x_visitvisit3 250mg e-09 treatadj_x_visitvisit4 200mg e-11 treatadj_x_visitvisit4 250mg e-12 treatadj_x_visitvisit5 200mg e-13 treatadj_x_visitvisit5 250mg e-15 treatadj_x_visitvisit6 200mg e-14 treatadj_x_visitvisit6 250mg e-12 treatadj_x_visitvisit7 200mg e-14 treatadj_x_visitvisit7 250mg e-12 5

6 Working correlation matrix n.time <- length(unique(dfl.onych$timeweeks.planned)) corm <- matrix(na, nrow = n.time, ncol = n.time) corm[lower.tri(corm)] <- gee.binun$geese$alpha corm [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] NA NA NA NA NA NA NA [2,] NA NA NA NA NA NA [3,] NA NA NA NA NA [4,] NA NA NA NA [5,] NA NA NA [6,] NA NA [7,] NA Odd ratios: # contrast matrix n.coef <- length(coef(gee.binun)) Contrast <- matrix(0, nrow = 3, ncol = n.coef) colnames(contrast) <- names(coef(gee.binun)) Contrast[1,c("treatadj_X_visitvisit1 200mg","treatadj_X_visitvisit7 200mg")] <- c(-1,1) Contrast[2,c("treatadj_X_visitvisit1 200mg","treatadj_X_visitvisit7 250mg")] <- c(-1,1) Contrast[3,c("treatadj_X_visitvisit7 200mg","treatadj_X_visitvisit7 250mg")] <- c(-1,1) # on the working scale resc <- esticon(gee.binun, cm = Contrast, conf.int = TRUE, joint.test = FALSE) # odd ratio cbind(estimate = exp(resc$estimate), + CIinf = exp(resc$estimate-1.96*resc$std.error), + CIsup = exp(resc$estimate+1.96*resc$std.error)) estimate CIinf CIsup [1,] [2,] [3,]

7 Predicted prevalences: sum(is.na(dfl.onych)) [1] 450 length(gee.binun$fitted.values) [1] 1908 NROW(dfL.onych[!is.na(dfL.onych$symptoms),]) [1] 1908 df.pred <- cbind(dfl.onych[!is.na(dfl.onych$symptoms),], + predicted.gee_un = gee.binun$fitted.values) df.pred <- df.pred[order(df.pred$visitnb),] xyplot(predicted.gee_un ~ visitnb, group = id, + data = df.pred[df.pred$id%in%c("1","3"),], + type = "l") 0.3 predicted.gee_un visitnb 7

8 # if add patient with missing data # R will connect non-consecutive points for those patients # leading to a wrong representation xyplot(log(predicted.gee_un/(1-predicted.gee_un)) ~ visitnb, group = id, + data = df.pred[df.pred$id%in%c("1","3"),], + type = "l") log(predicted.gee_un/(1 predicted.gee_un)) visitnb 8

9 Question 4: continuous time model Estimate the model gee.binctun <- geeglm(symptoms ~ time:treatment, + id = id, + data = dfl.onych, + subset = dfl.onych$visitnb < 6, + family = binomial(link = "logit"), corstr = "unstructured") summary(gee.binctun) Call: geeglm(formula = symptoms ~ time:treatment, family = binomial(link = "logit"), data = dfl.onych, subset = dfl.onych$visitnb < 6, id = id, corstr = "unstructured") Coefficients: Estimate Std.err Wald Pr( W ) (Intercept) e-07 *** time:treatment200mg e-08 *** time:treatment250mg e-09 *** --- Signif. codes: 0 '***' '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Estimated Scale Parameters: Estimate Std.err (Intercept) Correlation: Structure = unstructured Link = identity Estimated Correlation Parameters: Estimate Std.err alpha.1: alpha.1: alpha.1: alpha.1: alpha.2: alpha.2: alpha.2: alpha.3: alpha.3: alpha.4: Number of clusters: 294 Maximum cluster size: 5 9

10 Compute the odd ratios # contrast matrix n.coef <- length(coef(gee.binctun)) Contrast <- matrix(0, nrow = 3, ncol = n.coef) colnames(contrast) <- names(coef(gee.binctun)) Contrast[1,c("time:treatment200mg")] <- 1 Contrast[2,c("time:treatment250mg")] <- 1 Contrast[3,c("time:treatment200mg","time:treatment250mg")] <- c(1,-1) # on the working scale resc <- esticon(gee.binctun, cm = Contrast, conf.int = TRUE, joint.test = FALSE) # odd ratio cbind(estimate = exp(resc$estimate), + CIinf = exp(resc$estimate-1.96*resc$std.error), + CIsup = exp(resc$estimate+1.96*resc$std.error)) estimate CIinf CIsup [1,] [2,] [3,]

11 Question 5: conditional odds ratios 11

12 Question 6: glmer model Fit the model: glmer.bintime <- glmer(formula = symptoms ~ time:treatment + (1 id), + data = dfl.onych, + subset = dfl.onych$visitnb<6, + family = binomial(link = "logit")) summary(glmer.bintime) Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) [glmermod] Family: binomial ( logit ) Formula: symptoms ~ time:treatment + (1 id) Data: dfl.onych Subset: dfl.onych$visitnb < 6 AIC BIC loglik deviance df.resid Scaled residuals: Min 1Q Median 3Q Max Random effects: Groups Name Variance Std.Dev. id (Intercept) Number of obs: 1400, groups: id, 294 Fixed effects: Estimate Std. Error z value Pr( z ) (Intercept) < 2e-16 *** time:treatment200mg e-12 *** time:treatment250mg e-14 *** --- Signif. codes: 0 '***' '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Correlation of Fixed Effects: (Intr) tm:200 tm:trtmn tm:trtmn VarCorr(glmer.BinTime) Groups Name Std.Dev. id (Intercept)

13 Compute the odd ratios: n.coef <- length(fixef(glmer.bintime)) Contrast <- matrix(0, nrow = 3, ncol = n.coef) colnames(contrast) <- names(fixef(glmer.bintime)) Contrast[1,c("time:treatment200mg")] <- 1 Contrast[2,c("time:treatment250mg")] <- 1 Contrast[3,c("time:treatment200mg","time:treatment250mg")] <- c(1,-1) # on the working scale # one should use confint(glmer.bintime) # but to save computation time we use another function instead resc <- esticon(glmer.bintime, cm = Contrast, conf.int = TRUE, joint.test = FALSE) # odd ratio cbind(estimate = exp(resc$estimate), + CIinf = exp(resc$estimate-1.96*resc$std.error), + CIsup = exp(resc$estimate+1.96*resc$std.error)) estimate CIinf CIsup [1,] [2,] [3,]

14 Question 7: with a random slope Fit the model: system.time( + glmer.binslope <- glmer(formula = symptoms ~ time:treatment + (time id), + data = dfl.onych, + subset = dfl.onych$visitnb<6, + family = binomial(link = "logit")) + ) user system elapsed summary(glmer.binslope) Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) [glmermod] Family: binomial ( logit ) Formula: symptoms ~ time:treatment + (time id) Data: dfl.onych Subset: dfl.onych$visitnb < 6 AIC BIC loglik deviance df.resid Scaled residuals: Min 1Q Median 3Q Max Random effects: Groups Name Variance Std.Dev. Corr id (Intercept) time Number of obs: 1400, groups: id, 294 Fixed effects: Estimate Std. Error z value Pr( z ) (Intercept) < 2e-16 *** time:treatment200mg e-12 *** time:treatment250mg e-15 *** --- Signif. codes: 0 '***' '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Correlation of Fixed Effects: (Intr) tm:200 tm:trtmn tm:trtmn

15 Compute the odd ratios: n.coef <- length(fixef(glmer.binslope)) Contrast <- matrix(0, nrow = 3, ncol = n.coef) colnames(contrast) <- names(fixef(glmer.binslope)) Contrast[1,c("time:treatment200mg")] <- 1 Contrast[2,c("time:treatment250mg")] <- 1 Contrast[3,c("time:treatment200mg","time:treatment250mg")] <- c(1,-1) # on the working scale # one should use confint(glmer.binslope) instead resc <- esticon(glmer.binslope, cm = Contrast, conf.int = TRUE, joint.test = FALSE) # odd ratio cbind(estimate = exp(resc$estimate), + CIinf = exp(resc$estimate-1.96*resc$std.error), + CIsup = exp(resc$estimate+1.96*resc$std.error)) estimate CIinf CIsup [1,] 5.475e e e-04 [2,] 2.696e e e-04 [3,] 2.030e e e+01 15

16 Appendix A: Graphical display Question 2 Graphical display library(ggplot2, quietly = TRUE) gg.base <- ggplot(dfl.onych, aes(x = visitnb.factor, y = time, + color = factor(symptoms))) gg.base + geom_boxplot() + scale_colour_discrete(name = "symptoms") Warning: Removed 150 rows containing non-finite values (stat_boxplot). 15 time 10 symptoms visit1 visit2 visit3 visit4 visit5 visit6 visit7 visitnb.factor gg.base <- ggplot(dfl.onych, aes(x = timeweeks.planned, y = timeweeks, + group = id, color = factor(symptoms))) gg.base + geom_line() + scale_colour_discrete(name = "symptoms") + geom_abline(intercept = 0, slope Warning: Removed 101 rows containing missing values (geom_path). 16

17 80 60 timeweeks 40 symptoms 0 1 NA timeweeks.planned 17

Solution: anti-fungal treatment exercise

Solution: anti-fungal treatment exercise Solution: anti-fungal treatment exercise Course repeated measurements - R exercise class 5 December 5, 2017 Contents 1 Question 1: Import data 2 1.1 Data management.....................................

More information

Power analysis examples using R

Power analysis examples using R Power analysis examples using R Code The pwr package can be used to analytically compute power for various designs. The pwr examples below are adapted from the pwr package vignette, which is available

More information

lme4 Luke Chang Last Revised July 16, Fitting Linear Mixed Models with a Varying Intercept

lme4 Luke Chang Last Revised July 16, Fitting Linear Mixed Models with a Varying Intercept lme4 Luke Chang Last Revised July 16, 2010 1 Using lme4 1.1 Fitting Linear Mixed Models with a Varying Intercept We will now work through the same Ultimatum Game example from the regression section and

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

Analysis of binary repeated measures data with R

Analysis of binary repeated measures data with R Analysis of binary repeated measures data with R Right-handed basketball players take right and left-handed shots from 3 locations in a different random order for each player. Hit or miss is recorded.

More information

Non-Gaussian Response Variables

Non-Gaussian Response Variables Non-Gaussian Response Variables What is the Generalized Model Doing? The fixed effects are like the factors in a traditional analysis of variance or linear model The random effects are different A generalized

More information

Value Added Modeling

Value Added Modeling Value Added Modeling Dr. J. Kyle Roberts Southern Methodist University Simmons School of Education and Human Development Department of Teaching and Learning Background for VAMs Recall from previous lectures

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

Solution pigs exercise

Solution pigs exercise Solution pigs exercise Course repeated measurements - R exercise class 2 November 24, 2017 Contents 1 Question 1: Import data 3 1.1 Data management..................................... 3 1.2 Inspection

More information

Workshop 9.3a: Randomized block designs

Workshop 9.3a: Randomized block designs -1- Workshop 93a: Randomized block designs Murray Logan November 23, 16 Table of contents 1 Randomized Block (RCB) designs 1 2 Worked Examples 12 1 Randomized Block (RCB) designs 11 RCB design Simple Randomized

More information

Aedes egg laying behavior Erika Mudrak, CSCU November 7, 2018

Aedes egg laying behavior Erika Mudrak, CSCU November 7, 2018 Aedes egg laying behavior Erika Mudrak, CSCU November 7, 2018 Introduction The current study investivates whether the mosquito species Aedes albopictus preferentially lays it s eggs in water in containers

More information

Generalized Linear Mixed-Effects Models. Copyright c 2015 Dan Nettleton (Iowa State University) Statistics / 58

Generalized Linear Mixed-Effects Models. Copyright c 2015 Dan Nettleton (Iowa State University) Statistics / 58 Generalized Linear Mixed-Effects Models Copyright c 2015 Dan Nettleton (Iowa State University) Statistics 510 1 / 58 Reconsideration of the Plant Fungus Example Consider again the experiment designed to

More information

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

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

More information

STAT 526 Advanced Statistical Methodology

STAT 526 Advanced Statistical Methodology STAT 526 Advanced Statistical Methodology Fall 2017 Lecture Note 10 Analyzing Clustered/Repeated Categorical Data 0-0 Outline Clustered/Repeated Categorical Data Generalized Linear Mixed Models Generalized

More information

STAT3401: Advanced data analysis Week 10: Models for Clustered Longitudinal Data

STAT3401: Advanced data analysis Week 10: Models for Clustered Longitudinal Data STAT3401: Advanced data analysis Week 10: Models for Clustered Longitudinal Data Berwin Turlach School of Mathematics and Statistics Berwin.Turlach@gmail.com The University of Western Australia Models

More information

Contents. 1 Introduction: what is overdispersion? 2 Recognising (and testing for) overdispersion. 1 Introduction: what is overdispersion?

Contents. 1 Introduction: what is overdispersion? 2 Recognising (and testing for) overdispersion. 1 Introduction: what is overdispersion? Overdispersion, and how to deal with it in R and JAGS (requires R-packages AER, coda, lme4, R2jags, DHARMa/devtools) Carsten F. Dormann 07 December, 2016 Contents 1 Introduction: what is overdispersion?

More information

Hierarchical Linear Models (HLM) Using R Package nlme. Interpretation. 2 = ( x 2) u 0j. e ij

Hierarchical Linear Models (HLM) Using R Package nlme. Interpretation. 2 = ( x 2) u 0j. e ij Hierarchical Linear Models (HLM) Using R Package nlme Interpretation I. The Null Model Level 1 (student level) model is mathach ij = β 0j + e ij Level 2 (school level) model is β 0j = γ 00 + u 0j Combined

More information

STAT 510 Final Exam Spring 2015

STAT 510 Final Exam Spring 2015 STAT 510 Final Exam Spring 2015 Instructions: The is a closed-notes, closed-book exam No calculator or electronic device of any kind may be used Use nothing but a pen or pencil Please write your name and

More information

Introduction and Background to Multilevel Analysis

Introduction and Background to Multilevel Analysis Introduction and Background to Multilevel Analysis Dr. J. Kyle Roberts Southern Methodist University Simmons School of Education and Human Development Department of Teaching and Learning Background and

More information

A brief introduction to mixed models

A brief introduction to mixed models A brief introduction to mixed models University of Gothenburg Gothenburg April 6, 2017 Outline An introduction to mixed models based on a few examples: Definition of standard mixed models. Parameter estimation.

More information

Fitting mixed models in R

Fitting mixed models in R Fitting mixed models in R Contents 1 Packages 2 2 Specifying the variance-covariance matrix (nlme package) 3 2.1 Illustration:.................................... 3 2.2 Technical point: why to use as.numeric(time)

More information

PAPER 206 APPLIED STATISTICS

PAPER 206 APPLIED STATISTICS MATHEMATICAL TRIPOS Part III Thursday, 1 June, 2017 9:00 am to 12:00 pm PAPER 206 APPLIED STATISTICS Attempt no more than FOUR questions. There are SIX questions in total. The questions carry equal weight.

More information

Lecture 3.1 Basic Logistic LDA

Lecture 3.1 Basic Logistic LDA y Lecture.1 Basic Logistic LDA 0.2.4.6.8 1 Outline Quick Refresher on Ordinary Logistic Regression and Stata Women s employment example Cross-Over Trial LDA Example -100-50 0 50 100 -- Longitudinal Data

More information

Outline. Mixed models in R using the lme4 package Part 3: Longitudinal data. Sleep deprivation data. Simple longitudinal data

Outline. Mixed models in R using the lme4 package Part 3: Longitudinal data. Sleep deprivation data. Simple longitudinal data Outline Mixed models in R using the lme4 package Part 3: Longitudinal data Douglas Bates Longitudinal data: sleepstudy A model with random effects for intercept and slope University of Wisconsin - Madison

More information

Figure 36: Respiratory infection versus time for the first 49 children.

Figure 36: Respiratory infection versus time for the first 49 children. y BINARY DATA MODELS We devote an entire chapter to binary data since such data are challenging, both in terms of modeling the dependence, and parameter interpretation. We again consider mixed effects

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

Yet More Supporting Data Analysis for Unifying Life History Analysis for Inference of Fitness and Population Growth By Ruth G. Shaw, Charles J.

Yet More Supporting Data Analysis for Unifying Life History Analysis for Inference of Fitness and Population Growth By Ruth G. Shaw, Charles J. Yet More Supporting Data Analysis for Unifying Life History Analysis for Inference of Fitness and Population Growth By Ruth G. Shaw, Charles J. Geyer, Stuart Wagenius, Helen H. Hangelbroek, and Julie R.

More information

Contrasting Marginal and Mixed Effects Models Recall: two approaches to handling dependence in Generalized Linear Models:

Contrasting Marginal and Mixed Effects Models Recall: two approaches to handling dependence in Generalized Linear Models: Contrasting Marginal and Mixed Effects Models Recall: two approaches to handling dependence in Generalized Linear Models: Marginal models: based on the consequences of dependence on estimating model parameters.

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

lm statistics Chris Parrish

lm statistics Chris Parrish lm statistics Chris Parrish 2017-04-01 Contents s e and R 2 1 experiment1................................................. 2 experiment2................................................. 3 experiment3.................................................

More information

20. REML Estimation of Variance Components. Copyright c 2018 (Iowa State University) 20. Statistics / 36

20. REML Estimation of Variance Components. Copyright c 2018 (Iowa State University) 20. Statistics / 36 20. REML Estimation of Variance Components Copyright c 2018 (Iowa State University) 20. Statistics 510 1 / 36 Consider the General Linear Model y = Xβ + ɛ, where ɛ N(0, Σ) and Σ is an n n positive definite

More information

Multivariate Statistics in Ecology and Quantitative Genetics Summary

Multivariate Statistics in Ecology and Quantitative Genetics Summary Multivariate Statistics in Ecology and Quantitative Genetics Summary Dirk Metzler & Martin Hutzenthaler http://evol.bio.lmu.de/_statgen 5. August 2011 Contents Linear Models Generalized Linear Models Mixed-effects

More information

Overdispersion Workshop in generalized linear models Uppsala, June 11-12, Outline. Overdispersion

Overdispersion Workshop in generalized linear models Uppsala, June 11-12, Outline. Overdispersion Biostokastikum Overdispersion is not uncommon in practice. In fact, some would maintain that overdispersion is the norm in practice and nominal dispersion the exception McCullagh and Nelder (1989) Overdispersion

More information

Introduction to Linear Mixed Models: Modeling continuous longitudinal outcomes

Introduction to Linear Mixed Models: Modeling continuous longitudinal outcomes 1/64 to : Modeling continuous longitudinal outcomes Dr Cameron Hurst cphurst@gmail.com CEU, ACRO and DAMASAC, Khon Kaen University 4 th Febuary, 2557 2/64 Some motivational datasets Before we start, I

More information

Subject-specific observed profiles of log(fev1) vs age First 50 subjects in Six Cities Study

Subject-specific observed profiles of log(fev1) vs age First 50 subjects in Six Cities Study Subject-specific observed profiles of log(fev1) vs age First 50 subjects in Six Cities Study 1.4 0.0-6 7 8 9 10 11 12 13 14 15 16 17 18 19 age Model 1: A simple broken stick model with knot at 14 fit with

More information

Outline. Statistical inference for linear mixed models. One-way ANOVA in matrix-vector form

Outline. Statistical inference for linear mixed models. One-way ANOVA in matrix-vector form Outline Statistical inference for linear mixed models Rasmus Waagepetersen Department of Mathematics Aalborg University Denmark general form of linear mixed models examples of analyses using linear mixed

More information

Correlated Data: Linear Mixed Models with Random Intercepts

Correlated Data: Linear Mixed Models with Random Intercepts 1 Correlated Data: Linear Mixed Models with Random Intercepts Mixed Effects Models This lecture introduces linear mixed effects models. Linear mixed models are a type of regression model, which generalise

More information

Linear Regression Models P8111

Linear Regression Models P8111 Linear Regression Models P8111 Lecture 25 Jeff Goldsmith April 26, 2016 1 of 37 Today s Lecture Logistic regression / GLMs Model framework Interpretation Estimation 2 of 37 Linear regression Course started

More information

Mixed effects models

Mixed effects models Mixed effects models The basic theory and application in R Mitchel van Loon Research Paper Business Analytics Mixed effects models The basic theory and application in R Author: Mitchel van Loon Research

More information

Mixed models in R using the lme4 package Part 5: Generalized linear mixed models

Mixed models in R using the lme4 package Part 5: Generalized linear mixed models Mixed models in R using the lme4 package Part 5: Generalized linear mixed models Douglas Bates Madison January 11, 2011 Contents 1 Definition 1 2 Links 2 3 Example 7 4 Model building 9 5 Conclusions 14

More information

R code and output of examples in text. Contents. De Jong and Heller GLMs for Insurance Data R code and output. 1 Poisson regression 2

R code and output of examples in text. Contents. De Jong and Heller GLMs for Insurance Data R code and output. 1 Poisson regression 2 R code and output of examples in text Contents 1 Poisson regression 2 2 Negative binomial regression 5 3 Quasi likelihood regression 6 4 Logistic regression 6 5 Ordinal regression 10 6 Nominal regression

More information

Introduction to Within-Person Analysis and RM ANOVA

Introduction to Within-Person Analysis and RM ANOVA Introduction to Within-Person Analysis and RM ANOVA Today s Class: From between-person to within-person ANOVAs for longitudinal data Variance model comparisons using 2 LL CLP 944: Lecture 3 1 The Two Sides

More information

Mixed-effects Maximum Likelihood Difference Scaling

Mixed-effects Maximum Likelihood Difference Scaling Mixed-effects Maximum Likelihood Difference Scaling Kenneth Knoblauch Inserm U 846 Stem Cell and Brain Research Institute Dept. Integrative Neurosciences Bron, France Laurence T. Maloney Department of

More information

7/28/15. Review Homework. Overview. Lecture 6: Logistic Regression Analysis

7/28/15. Review Homework. Overview. Lecture 6: Logistic Regression Analysis Lecture 6: Logistic Regression Analysis Christopher S. Hollenbeak, PhD Jane R. Schubart, PhD The Outcomes Research Toolbox Review Homework 2 Overview Logistic regression model conceptually Logistic regression

More information

Mixed models in R using the lme4 package Part 5: Generalized linear mixed models

Mixed models in R using the lme4 package Part 5: Generalized linear mixed models Mixed models in R using the lme4 package Part 5: Generalized linear mixed models Douglas Bates 2011-03-16 Contents 1 Generalized Linear Mixed Models Generalized Linear Mixed Models When using linear mixed

More information

Stat 579: Generalized Linear Models and Extensions

Stat 579: Generalized Linear Models and Extensions Stat 579: Generalized Linear Models and Extensions Linear Mixed Models for Longitudinal Data Yan Lu April, 2018, week 14 1 / 64 Data structure and Model t1 t2 tn i 1st subject y 11 y 12 y 1n1 2nd subject

More information

Mixed models in R using the lme4 package Part 7: Generalized linear mixed models

Mixed models in R using the lme4 package Part 7: Generalized linear mixed models Mixed models in R using the lme4 package Part 7: Generalized linear mixed models Douglas Bates University of Wisconsin - Madison and R Development Core Team University of

More information

SAS Syntax and Output for Data Manipulation: CLDP 944 Example 3a page 1

SAS Syntax and Output for Data Manipulation: CLDP 944 Example 3a page 1 CLDP 944 Example 3a page 1 From Between-Person to Within-Person Models for Longitudinal Data The models for this example come from Hoffman (2015) chapter 3 example 3a. We will be examining the extent to

More information

R Analysis Example Replication C11

R Analysis Example Replication C11 R Analysis Example Replication C11 # Chapter 11 Longitudinal Analysis HRS data # Use data sets previously prepared in SAS for this chapter to reduce code burden in R # Complete Case 1 Wave # 11.3.1 Example:

More information

PAPER 218 STATISTICAL LEARNING IN PRACTICE

PAPER 218 STATISTICAL LEARNING IN PRACTICE MATHEMATICAL TRIPOS Part III Thursday, 7 June, 2018 9:00 am to 12:00 pm PAPER 218 STATISTICAL LEARNING IN PRACTICE Attempt no more than FOUR questions. There are SIX questions in total. The questions carry

More information

R Output for Linear Models using functions lm(), gls() & glm()

R Output for Linear Models using functions lm(), gls() & glm() LM 04 lm(), gls() &glm() 1 R Output for Linear Models using functions lm(), gls() & glm() Different kinds of output related to linear models can be obtained in R using function lm() {stats} in the base

More information

Stat 5303 (Oehlert): Randomized Complete Blocks 1

Stat 5303 (Oehlert): Randomized Complete Blocks 1 Stat 5303 (Oehlert): Randomized Complete Blocks 1 > library(stat5303libs);library(cfcdae);library(lme4) > immer Loc Var Y1 Y2 1 UF M 81.0 80.7 2 UF S 105.4 82.3 3 UF V 119.7 80.4 4 UF T 109.7 87.2 5 UF

More information

Model and Working Correlation Structure Selection in GEE Analyses of Longitudinal Data

Model and Working Correlation Structure Selection in GEE Analyses of Longitudinal Data The 3rd Australian and New Zealand Stata Users Group Meeting, Sydney, 5 November 2009 1 Model and Working Correlation Structure Selection in GEE Analyses of Longitudinal Data Dr Jisheng Cui Public Health

More information

I r j Binom(m j, p j ) I L(, ; y) / exp{ y j + (x j y j ) m j log(1 + e + x j. I (, y) / L(, ; y) (, )

I r j Binom(m j, p j ) I L(, ; y) / exp{ y j + (x j y j ) m j log(1 + e + x j. I (, y) / L(, ; y) (, ) Today I Bayesian analysis of logistic regression I Generalized linear mixed models I CD on fixed and random effects I HW 2 due February 28 I Case Studies SSC 2014 Toronto I March/April: Semi-parametric

More information

Statistical Methods III Statistics 212. Problem Set 2 - Answer Key

Statistical Methods III Statistics 212. Problem Set 2 - Answer Key Statistical Methods III Statistics 212 Problem Set 2 - Answer Key 1. (Analysis to be turned in and discussed on Tuesday, April 24th) The data for this problem are taken from long-term followup of 1423

More information

Generalized linear models for binary data. A better graphical exploratory data analysis. The simple linear logistic regression model

Generalized linear models for binary data. A better graphical exploratory data analysis. The simple linear logistic regression model Stat 3302 (Spring 2017) Peter F. Craigmile Simple linear logistic regression (part 1) [Dobson and Barnett, 2008, Sections 7.1 7.3] Generalized linear models for binary data Beetles dose-response example

More information

Logistic Regressions. Stat 430

Logistic Regressions. Stat 430 Logistic Regressions Stat 430 Final Project Final Project is, again, team based You will decide on a project - only constraint is: you are supposed to use techniques for a solution that are related to

More information

Exam Applied Statistical Regression. Good Luck!

Exam Applied Statistical Regression. Good Luck! Dr. M. Dettling Summer 2011 Exam Applied Statistical Regression Approved: Tables: Note: Any written material, calculator (without communication facility). Attached. All tests have to be done at the 5%-level.

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

Booklet of Code and Output for STAD29/STA 1007 Midterm Exam

Booklet of Code and Output for STAD29/STA 1007 Midterm Exam Booklet of Code and Output for STAD29/STA 1007 Midterm Exam List of Figures in this document by page: List of Figures 1 NBA attendance data........................ 2 2 Regression model for NBA attendances...............

More information

R Hints for Chapter 10

R Hints for Chapter 10 R Hints for Chapter 10 The multiple logistic regression model assumes that the success probability p for a binomial random variable depends on independent variables or design variables x 1, x 2,, x k.

More information

Introduction to logistic regression

Introduction to logistic regression Introduction to logistic regression Tuan V. Nguyen Professor and NHMRC Senior Research Fellow Garvan Institute of Medical Research University of New South Wales Sydney, Australia What we are going to learn

More information

cor(dataset$measurement1, dataset$measurement2, method= pearson ) cor.test(datavector1, datavector2, method= pearson )

cor(dataset$measurement1, dataset$measurement2, method= pearson ) cor.test(datavector1, datavector2, method= pearson ) Tutorial 7: Correlation and Regression Correlation Used to test whether two variables are linearly associated. A correlation coefficient (r) indicates the strength and direction of the association. A correlation

More information

Bayesian analysis of logistic regression

Bayesian analysis of logistic regression Today Bayesian analysis of logistic regression Generalized linear mixed models CD on fixed and random effects HW 2 due February 28 Case Studies SSC 2014 Toronto March/April: Semi-parametric regression

More information

Logistic Regression. 1 Analysis of the budworm moth data 1. 2 Estimates and confidence intervals for the parameters 2

Logistic Regression. 1 Analysis of the budworm moth data 1. 2 Estimates and confidence intervals for the parameters 2 Logistic Regression Ulrich Halekoh, Jørgen Vinslov Hansen, Søren Højsgaard Biometry Research Unit Danish Institute of Agricultural Sciences March 31, 2006 Contents 1 Analysis of the budworm moth data 1

More information

Generalized Linear Models. stat 557 Heike Hofmann

Generalized Linear Models. stat 557 Heike Hofmann Generalized Linear Models stat 557 Heike Hofmann Outline Intro to GLM Exponential Family Likelihood Equations GLM for Binomial Response Generalized Linear Models Three components: random, systematic, link

More information

Temporal Learning: IS50 prior RT

Temporal Learning: IS50 prior RT Temporal Learning: IS50 prior RT Loading required package: Matrix Jihyun Suh 1/27/2016 This data.table install has not detected OpenMP support. It will work but slower in single threaded m Attaching package:

More information

Supplemental Resource: Brain and Cognitive Sciences Statistics & Visualization for Data Analysis & Inference January (IAP) 2009

Supplemental Resource: Brain and Cognitive Sciences Statistics & Visualization for Data Analysis & Inference January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu Supplemental Resource: Brain and Cognitive Sciences Statistics & Visualization for Data Analysis & Inference January (IAP) 2009 For information about citing these

More information

Introduction to mtm: An R Package for Marginalized Transition Models

Introduction to mtm: An R Package for Marginalized Transition Models Introduction to mtm: An R Package for Marginalized Transition Models Bryan A. Comstock and Patrick J. Heagerty Department of Biostatistics University of Washington 1 Introduction Marginalized transition

More information

M. H. Gonçalves 1 M. S. Cabral 2 A. Azzalini 3

M. H. Gonçalves 1 M. S. Cabral 2 A. Azzalini 3 M. H. Gonçalves 1 M. S. Cabral 2 A. Azzalini 3 1 University of Algarve, Portugal 2 University of Lisbon, Portugal 3 Università di Padova, Italy user!2010, July 21-23 1 2 3 4 5 What is bild? an R. parametric

More information

HW 2 due March 6 random effects and mixed effects models ELM Ch. 8 R Studio Cheatsheets In the News: homeopathic vaccines

HW 2 due March 6 random effects and mixed effects models ELM Ch. 8 R Studio Cheatsheets In the News: homeopathic vaccines Today HW 2 due March 6 random effects and mixed effects models ELM Ch. 8 R Studio Cheatsheets In the News: homeopathic vaccines STA 2201: Applied Statistics II March 4, 2015 1/35 A general framework y

More information

Outline. Mixed models in R using the lme4 package Part 5: Generalized linear mixed models. Parts of LMMs carried over to GLMMs

Outline. Mixed models in R using the lme4 package Part 5: Generalized linear mixed models. Parts of LMMs carried over to GLMMs Outline Mixed models in R using the lme4 package Part 5: Generalized linear mixed models Douglas Bates University of Wisconsin - Madison and R Development Core Team UseR!2009,

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

MLDS: Maximum Likelihood Difference Scaling in R

MLDS: Maximum Likelihood Difference Scaling in R MLDS: Maximum Likelihood Difference Scaling in R Kenneth Knoblauch Inserm U 846 Département Neurosciences Intégratives Institut Cellule Souche et Cerveau Bron, France Laurence T. Maloney Department of

More information

A Generalized Linear Model for Binomial Response Data. Copyright c 2017 Dan Nettleton (Iowa State University) Statistics / 46

A Generalized Linear Model for Binomial Response Data. Copyright c 2017 Dan Nettleton (Iowa State University) Statistics / 46 A Generalized Linear Model for Binomial Response Data Copyright c 2017 Dan Nettleton (Iowa State University) Statistics 510 1 / 46 Now suppose that instead of a Bernoulli response, we have a binomial response

More information

samplesizelogisticcasecontrol Package

samplesizelogisticcasecontrol Package samplesizelogisticcasecontrol Package January 31, 2017 > library(samplesizelogisticcasecontrol) Random data generation functions Let X 1 and X 2 be two variables with a bivariate normal ditribution with

More information

ECLT 5810 Linear Regression and Logistic Regression for Classification. Prof. Wai Lam

ECLT 5810 Linear Regression and Logistic Regression for Classification. Prof. Wai Lam ECLT 5810 Linear Regression and Logistic Regression for Classification Prof. Wai Lam Linear Regression Models Least Squares Input vectors is an attribute / feature / predictor (independent variable) The

More information

Introduction to lnmle: An R Package for Marginally Specified Logistic-Normal Models for Longitudinal Binary Data

Introduction to lnmle: An R Package for Marginally Specified Logistic-Normal Models for Longitudinal Binary Data Introduction to lnmle: An R Package for Marginally Specified Logistic-Normal Models for Longitudinal Binary Data Bryan A. Comstock and Patrick J. Heagerty Department of Biostatistics University of Washington

More information

Discriminant Analysis

Discriminant Analysis Chapter 16 Discriminant Analysis A researcher collected data on two external features for two (known) sub-species of an insect. She can use discriminant analysis to find linear combinations of the features

More information

STATS216v Introduction to Statistical Learning Stanford University, Summer Midterm Exam (Solutions) Duration: 1 hours

STATS216v Introduction to Statistical Learning Stanford University, Summer Midterm Exam (Solutions) Duration: 1 hours Instructions: STATS216v Introduction to Statistical Learning Stanford University, Summer 2017 Remember the university honor code. Midterm Exam (Solutions) Duration: 1 hours Write your name and SUNet ID

More information

Generalized Linear and Nonlinear Mixed-Effects Models

Generalized Linear and Nonlinear Mixed-Effects Models Generalized Linear and Nonlinear Mixed-Effects Models Douglas Bates University of Wisconsin - Madison and R Development Core Team University of Potsdam August 8, 2008 Outline

More information

Analysing categorical data using logit models

Analysing categorical data using logit models Analysing categorical data using logit models Graeme Hutcheson, University of Manchester The lecture notes, exercises and data sets associated with this course are available for download from: www.research-training.net/manchester

More information

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

A Handbook of Statistical Analyses Using R. Brian S. Everitt and Torsten Hothorn A Handbook of Statistical Analyses Using R Brian S. Everitt and Torsten Hothorn CHAPTER 6 Logistic Regression and Generalised Linear Models: Blood Screening, Women s Role in Society, and Colonic Polyps

More information

Name: Biostatistics 1 st year Comprehensive Examination: Applied in-class exam. June 8 th, 2016: 9am to 1pm

Name: Biostatistics 1 st year Comprehensive Examination: Applied in-class exam. June 8 th, 2016: 9am to 1pm Name: Biostatistics 1 st year Comprehensive Examination: Applied in-class exam June 8 th, 2016: 9am to 1pm Instructions: 1. This is exam is to be completed independently. Do not discuss your work with

More information

Generalised linear models. Response variable can take a number of different formats

Generalised linear models. Response variable can take a number of different formats Generalised linear models Response variable can take a number of different formats Structure Limitations of linear models and GLM theory GLM for count data GLM for presence \ absence data GLM for proportion

More information

Logistic Regression - problem 6.14

Logistic Regression - problem 6.14 Logistic Regression - problem 6.14 Let x 1, x 2,, x m be given values of an input variable x and let Y 1,, Y m be independent binomial random variables whose distributions depend on the corresponding values

More information

Outline. Linear OLS Models vs: Linear Marginal Models Linear Conditional Models. Random Intercepts Random Intercepts & Slopes

Outline. Linear OLS Models vs: Linear Marginal Models Linear Conditional Models. Random Intercepts Random Intercepts & Slopes Lecture 2.1 Basic Linear LDA 1 Outline Linear OLS Models vs: Linear Marginal Models Linear Conditional Models Random Intercepts Random Intercepts & Slopes Cond l & Marginal Connections Empirical Bayes

More information

MODULE 6 LOGISTIC REGRESSION. Module Objectives:

MODULE 6 LOGISTIC REGRESSION. Module Objectives: MODULE 6 LOGISTIC REGRESSION Module Objectives: 1. 147 6.1. LOGIT TRANSFORMATION MODULE 6. LOGISTIC REGRESSION Logistic regression models are used when a researcher is investigating the relationship between

More information

Random and Mixed Effects Models - Part II

Random and Mixed Effects Models - Part II Random and Mixed Effects Models - Part II Statistics 149 Spring 2006 Copyright 2006 by Mark E. Irwin Two-Factor Random Effects Model Example: Miles per Gallon (Neter, Kutner, Nachtsheim, & Wasserman, problem

More information

Statistics 203 Introduction to Regression Models and ANOVA Practice Exam

Statistics 203 Introduction to Regression Models and ANOVA Practice Exam Statistics 203 Introduction to Regression Models and ANOVA Practice Exam Prof. J. Taylor You may use your 4 single-sided pages of notes This exam is 7 pages long. There are 4 questions, first 3 worth 10

More information

Answer to exercise: Blood pressure lowering drugs

Answer to exercise: Blood pressure lowering drugs Answer to exercise: Blood pressure lowering drugs The data set bloodpressure.txt contains data from a cross-over trial, involving three different formulations of a drug for lowering of blood pressure:

More information

Lecture 9 STK3100/4100

Lecture 9 STK3100/4100 Lecture 9 STK3100/4100 27. October 2014 Plan for lecture: 1. Linear mixed models cont. Models accounting for time dependencies (Ch. 6.1) 2. Generalized linear mixed models (GLMM, Ch. 13.1-13.3) Examples

More information

UNIVERSITY OF TORONTO Faculty of Arts and Science

UNIVERSITY OF TORONTO Faculty of Arts and Science UNIVERSITY OF TORONTO Faculty of Arts and Science December 2013 Final Examination STA442H1F/2101HF Methods of Applied Statistics Jerry Brunner Duration - 3 hours Aids: Calculator Model(s): Any calculator

More information

On the Inference of the Logistic Regression Model

On the Inference of the Logistic Regression Model On the Inference of the Logistic Regression Model 1. Model ln =(; ), i.e. = representing false. The linear form of (;) is entertained, i.e. ((;)) ((;)), where ==1 ;, with 1 representing true, 0 ;= 1+ +

More information

MS&E 226: Small Data

MS&E 226: Small Data MS&E 226: Small Data Lecture 15: Examples of hypothesis tests (v5) Ramesh Johari ramesh.johari@stanford.edu 1 / 32 The recipe 2 / 32 The hypothesis testing recipe In this lecture we repeatedly apply the

More information

Outline for today. Two-way analysis of variance with random effects

Outline for today. Two-way analysis of variance with random effects Outline for today Two-way analysis of variance with random effects Rasmus Waagepetersen Department of Mathematics Aalborg University Denmark Two-way ANOVA using orthogonal projections March 4, 2018 1 /

More information

Hands on cusp package tutorial

Hands on cusp package tutorial Hands on cusp package tutorial Raoul P. P. P. Grasman July 29, 2015 1 Introduction The cusp package provides routines for fitting a cusp catastrophe model as suggested by (Cobb, 1978). The full documentation

More information

Models for Count and Binary Data. Poisson and Logistic GWR Models. 24/07/2008 GWR Workshop 1

Models for Count and Binary Data. Poisson and Logistic GWR Models. 24/07/2008 GWR Workshop 1 Models for Count and Binary Data Poisson and Logistic GWR Models 24/07/2008 GWR Workshop 1 Outline I: Modelling counts Poisson regression II: Modelling binary events Logistic Regression III: Poisson Regression

More information

Introduction to SAS proc mixed

Introduction to SAS proc mixed Faculty of Health Sciences Introduction to SAS proc mixed Analysis of repeated measurements, 2017 Julie Forman Department of Biostatistics, University of Copenhagen 2 / 28 Preparing data for analysis The

More information

Solutions to obligatorisk oppgave 2, STK2100

Solutions to obligatorisk oppgave 2, STK2100 Solutions to obligatorisk oppgave 2, STK2100 Vinnie Ko May 14, 2018 Disclaimer: This document is made solely for my own personal use and can contain many errors. Oppgave 1 We load packages and read data

More information