[R] Fitting model with response and day bias

From: Bart Joosen <bartjoosen_at_hotmail.com>
Date: Wed, 09 May 2007 14:41:59 +0000


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)     }

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?



R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 09 May 2007 - 14:58:15 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 09 May 2007 - 15:01:48 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.