Skip to content

Commit

Permalink
Mean curves for plot, kinda not perfect though
Browse files Browse the repository at this point in the history
  • Loading branch information
philchalmers committed Mar 22, 2012
1 parent 147b280 commit 1463264
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions R/OLScurve.R
Expand Up @@ -201,15 +201,23 @@ print.OLScurve <- function(x, group = NULL, SE = TRUE, digits = 3, ...){
#' @rdname OLScurve
#' @method plot OLScurve
plot.OLScurve <- function(x, group = NULL, sep = FALSE, ...){
data <- x$data
data <- data.frame(x$pred)
N <- nrow(data)
fn <- fn1 <- x$formula
id.o <- id <- as.numeric(rownames(data))
data <- data.frame(data)

plotOLScurve <- function(data, fn, group = NULL, layout = NULL) {
data <- data.frame(data)
if(is.null(data$id)) data$id.o<-1:nrow(data)
id.o <- id <- as.numeric(rownames(data))
meanpred <- list(colMeans(x$pred))
IND <- rep(1, N)
###FIXME
# if(!is.null(group)){
# meannames <- unique(group)
# ID <- 1:length(meannames)
# for(i in 1:length(meannames))
# meanpred[[i]] <- colMeans(data[id[group == meannames[i]], ])
# for(i in 1:N) IND[i] <- ID[group[i] == meannames]
# }

plotOLScurve <- function(data, fn, meanpred, ind = IND, group = NULL, layout = NULL) {
if(is.null(data$id)) data$id.o <- 1:nrow(data)
else data$id.o <- data$id
if(!is.null(group))
data$group <- group
Expand All @@ -221,10 +229,12 @@ plot.OLScurve <- function(x, group = NULL, sep = FALSE, ...){
data$id.o <- paste(data$group,data$id.o)
plot.fn <- y ~ time | group
}

data$ind <- ind

ys <- colnames(data)[!(colnames(data)=="id")&
!(colnames(data)=="group")&
!(colnames(data)=="id.o")]
!(colnames(data)=="id.o") &
!(colnames(data)=="ind")]

datalg <- reshape(data, idvar="id",
varying = list(ys),
Expand All @@ -238,19 +248,21 @@ plot.OLScurve <- function(x, group = NULL, sep = FALSE, ...){
fn1 <- paste(ch[2],ch[1],ch[3])

###### PLOT INDIVIDUAL PARTICIPANTS ######
mypanel = function(x, y, ...){
fn2 <- as.formula(fn1)
fm <- lm(fn2)
panel.lines(x,predict(fm))
mypanel = function(x, y, meanpred, IND, subscripts, ...){
panel.lines(x,y)
grouppred <- meanpred[[1]] ###FIXME
panel.lines(x, grouppred, lwd=2, col='black')
}
groupPlots <-xyplot( plot.fn , datalg, groups = factor(id),
groupPlots <- xyplot(plot.fn, datalg, groups = factor(id),
layout = layout,
xlab = "Time",
ylab = "Predicted",
main = 'Group Plots',
meanpred = meanpred,
IND = datalg$ind,
panel = panel.superpose,
panel.groups = mypanel)
print(groupPlots)
}
plotOLScurve(data, fn, group, layout = NULL)
plotOLScurve(data, fn, meanpred, IND, group, layout = NULL)
}

0 comments on commit 1463264

Please sign in to comment.