[R-sig-ME] Help with mixed models function

Cody Likavec codylikavec at gmail.com
Wed Aug 14 15:05:35 CEST 2013


(I apologize if I'm not replying to the listserv correctly).

That worked for me (in a way). The lines below worked in my function
	linfcts2 <- eval(parse(text=paste("mcp(",paste(iv,' ="Tukey"
',collapse=','),')')));
	pairwise2 <- summary(glht(owobanova , linfct = linfcts2));

So I have the between subjects pairwise comparisons.  However, when I want
to compare the interaction between "iv" and "contrasts" I'm getting an
error. Below is my input and my error:
	linfcts3 <- eval(parse(text=paste("mcp(",paste(iv,'*',contrasts,'
="Tukey" ',collapse=','),')')));
	pairwise3 <- summary(glht(owobanova , linfct = linfcts3));

Error in paste(iv, "*", contrasts, " =\"Tukey\" ", collapse = ",") : 
  cannot coerce type 'closure' to vector of type 'character'

-----Original Message-----
From: Hugo.Mildenberger at web.de [mailto:Hugo.Mildenberger at web.de] 
Sent: Tuesday, August 13, 2013 6:56 PM
To: Cody Likavec
Cc: r-sig-mixed-models at r-project.org
Subject: Re: [R-sig-ME] Help with mixed models function

Cody,

the mcp function from the multcomp package expects a named argument list,
not an array of strings: 

 iv        <- c('a','b','c')
 linfcts   <- eval(parse(text=paste("mcp(",paste(iv,'= "Tukey"
',collapse=','),')')));
 pairwise2 <- summary(glht(owobanova , linfct = linfcts));
 
Hugo 


On Tue, 13 Aug 2013 16:01:43 -0400
"Cody Likavec" <codylikavec at gmail.com> wrote:

> Hello,
> 
> I'm trying to write a function to automate a mixed-model ANOVA 
> (one-between, one-within). I've gotten most of it to work. I can throw 
> in my data and get output for the within and between subjects effects. 
> However, when I try to do the pairwise comparisons, I'm running into a 
> wall on how to actually run them, since they're embedded in the 
> function. I get stuck once I get to "pair2". Because the "iv" is going 
> to dynamically change, I can't seem to figure out what to use to give 
> me output that will dynamically change based on what I enter into the 
> function. Below is what I have for the full function.
> 
> onewithin.onebetween <- function(dvs, iv, id, data){
> 
> 
> 	dataframe <- cbind(data[id], data[dvs], data[iv])
> 
> 	means <- sapply(split(dataframe[dvs], data[iv]), colMeans,
> na.rm=TRUE)
> 	sds <- sapply(split(dataframe[dvs], data[iv]), sd, na.rm=TRUE)
> 
> 	shapiros <- sapply(data[dvs], shapiro.test);
> 
> 
> 	myexpr.df <- make.rm(constant=c(id, iv), repeated=c(dvs), 
> data=dataframe);
> 	
> 
> 	formula <- as.formula(paste("repdat~contrasts +",iv, "+ 
> contrasts*",iv));
> 	random <- as.formula(paste("~1|",id))
> 	owobanova <- lme(formula, data=myexpr.df, random=random);
> 
> 	
> 	anova <- anova(owobanova);
> 
> 	#pairwise1 <- summary(glht(owobanova , linfct = mcp(contrasts = 
> "Tukey")));
> 
> 	#pair2 <- paste(iv,'= "Tukey" ');
> 
> 	#pairwise2 <- summary(glht(owobanova , linfct = mcp(pair2)));
> 
> 	#pair3 <- paste(contrasts,"*",iv,'= "Tukey" ');
> 
> 	#pairwise3 < summary(glht(owobanova , linfct = mcp(pair3)));
> 
> 	output <- list();
> 
> 	output$means <- as.list(as.data.frame(means));
> 	output$sds <- as.list(as.data.frame(sds));
> 	output$shapiros <- as.list(as.data.frame(shapiros));
> 	output$anova2 <- anova;
> 	#output$pairwise <- as.list(unclass(pairwise1$test$coefficients));
> 	#output$pairwise2 <- as.list(unclass(pairwise1$test$pvalues));
> 	#output$pairwise3 <- as.list(unclass(pairwise2$test$coefficients));
> 	#output$pairwise4 <- as.list(unclass(pairwise2$test$pvalues));
> 	#output$pairwise5 <- as.list(unclass(pairwise3$test$coefficients));
> 	#output$pairwise6 <- as.list(unclass(pairwise3$test$pvalues));
> 	return(output)
> 	
> }
> 
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list 
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models


--



More information about the R-sig-mixed-models mailing list