[R] Fitting model with response and day bias
Bart Joosen
bartjoosen at hotmail.com
Wed May 9 16:41:59 CEST 2007
Hi,
I'm trying to fit a model which has a response bias, but also a day to day
bias.
If I try to simulate the data, I don't get the right values with optim, and
also I can't
use the function to give a prediction interval.
My simulated data are:
DF <- as.data.frame(cbind(x=rep(1:10,2),dag=rep(1:2,each=10)))
bias <- c(-0.2,0.5)
DF$y <- ((DF$x-0.1) * 5)+2 + bias[DF$dag]+rnorm(20,0,sd=0.5)
Which I try to fit with:
fn <- function(x){
a <- x[1]
b <- x[2]
c <- x[2]
sum((DF$y - (((DF$x-c)*a)+b + x[DF$dag+2]))^2)
}
optim(c(1,1,1,1,1),fn)
But with poor succes.
Also, in the real model, I have a response which is y/time (like in
lm(y/time~x1 + x2,...) ) , but if I put the time variable at the right side
(lm(y~I(x1 + x2)*time) , it gets an coefficient.
Is there a way to avoid this?
Thanks
Bart
More information about the R-help
mailing list