Skip to content
Prev 314936 / 398506 Next

Using objects within functions in formulas

On Jan 9, 2013, at 8:53 AM, Aidan MacNamara wrote:

            
Generally regression functions in R will be expecting to get one  
'data' argument and build formulas using column names from that object.

  test1 <- function(x2, y2, w2) {
    w3 <- cbind(w2, x2, x2)
	print(str(w3))
	form = as.formula(paste("y2 ~ x2 +" ,paste("(1|", names(w2), ")",
collapse=" + ", sep="")))
	m1 = glmer(form, data=w3); print(summary(m1))
	return(m1)
     }

model1 = test1(x2=x1, y2=y1, w2=w1)
David Winsemius, MD
Alameda, CA, USA