How do I structure data to use R lmer -



How do I structure data to use R lmer -

i trying trending analysis of reliability data. typical case determine if 10-year trend exists in demand rate specified scheme @ specified plants.

i trying generate test case bit confused how construction data. trend years range 2004 2013. in test case have, each year, 10 systems demands have been counted. using distributed demand counts different means , variances each year. of course of study real info not have same scheme count each year, , demand counts not distributed.

the next r code produces info frame (df1) seems reasonable me:

yr <- 2004:2013 y2004 <- rnorm(10, 10, 3) y2005 <- rnorm(10, 11, 2) y2006 <- rnorm(10, 12, 1) y2007 <- rnorm(10, 13, 5) y2008 <- rnorm(10, 14, 3) y2009 <- rnorm(10, 15, 4) y2010 <- rnorm(10, 16, 1) y2011 <- rnorm(10, 17, 2) y2012 <- rnorm(10, 18, 4) y2013 <- rnorm(10, 19, 1) df1 <- data.frame(cbind(yr), y2004, y2005, y2006, y2007, y2008, y2009, y2010, y2011, y2012,y2013) df2 <- data.frame(cbind(rep(0.0, 100), rep(0.0, 100))) names(df2) <- c("x", "y") k <-1 (i in 1:10) { (j in 1:10) { df2$x[k] <- df1$yr[i] df2$y[k] <- df1[j,i+1] k <- k + 1 } } boxplot(y ~ x, df2)

anyway, first problem construction of df2 seems unnecessary given have info in df1 - it's phone call lmer seems require organization of df2. phone call lmer looks following:

fit <- lmer(y ~ x + (1|x), data=df2)

so there way utilize lmer without construction of df2, using df1 directly? or there improve way construction info entirely?

my sec problem not sure how utilize lmer want do. looking pool count info each year , fit mean demand count each year straight line. best fit should consider variance in info in each pooled year group. going correctly?

nearly plotting , modeling functions in r require info in "long" format (ie df2). if anything, skip construction of df1. if want generate df2 more directly, do

df2 <- do.call("rbind.data.frame", map(cbind, y=map(function(n,m,s) rnorm(n,m,s), 10, 10:19, c(3,2,1,5,3,4,1,2,3,1)), x=2004:2013))

r

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

java - Parsing XML, skip certain tags -

c# - ASP.NET MVC Sequence contains no matching element -