Given a set of samples that are measured before and after treatment.
The size of the treatment effect depends on the measurement value before treatment.
However, the number of measurements per sample, and the number of measurements before and after treatment vary in the set.
How do I estimate the coefficients $a$ and $b$ in the relationship $y = ax^b$ in this case?
(I'm not really asking about a power function regression analysis, more how to handle the odd number of data points before and after)
Here is some R code to exemplify the problem:
set.seed( 100 )
x.design <- factor(c(
1,1,1, 2, 3,3, 4,4,4,4
)) # each sample measured different number of times before
## generate a random profile for 4 samples
x0 <- runif(nlevels(x.design),max=10)
## add 10% CV to each measurment and expanding per the design
x <- unlist( sapply( seq_along(x0), function(i){
nn <- summary(x.design)[i]
xi <- x0[i]
rnorm( nn, mean=xi, sd=.1*xi )
}))
## two parameters to estimate in a y = a * x^b relationship:
a <- rnorm(1,mean=1, sd=.2)
b <- rnorm(1,mean=1.5, sd=.2)
## generate some y's along the same lines as we did with x:
y0 <- a*(x0**b)
y.design <- factor(c(
1, 2,2,2,2,2, 3,3,3, 4,4
))
## add noise in the same way
y <- unlist( sapply( seq_along(x0), function(i){
nn <- summary(y.design)[i]
yi <- y0[i]
rnorm( nn, mean=yi, sd=.1*yi )
}))
## graph the relationship using sample means:
plot( by( x, x.design, mean ), by( y, y.design, mean ) )
curve( a*x^b, add=T, col="blue" )
## data combine in a data.frame
rbind.data.frame(
data.frame(
Sample = x.design,
Value = x,
Treatment = "before"
),
data.frame(
Sample = y.design,
Value = y,
Treatment = "after"
)
)
EDIT: Added data.frame to combine both x and y
Now I could just use the mean per sample per treatment, and it wouldn't be very wrong, but it would be nice to take into account the power each sample lends to the estimation, seeing how they have different number of measurements.
I suspect this kind of problem must have been presented before, but I haven't been able to search for the right terms I guess.