Use of offset in lm regression - R

前端 未结 2 1077
难免孤独
难免孤独 2021-01-05 17:51

I have this code

dens <- read.table(\'DensPiu.csv\', header = FALSE)
fl <- read.table(\'FluxPiu.csv\', header = FALSE)
mydata <- data.frame(c(dens),         


        
相关标签:
2条回答
  • 2021-01-05 18:16

    In fact, the real issue here is that you should specify offset with a vector whose length is the same as the number of rows (or the length, if data is composed as a vector) of your data. The following code will do your job as expected:

    regression <- lm(y ~ I(x-x0)-1, offset = rep(y0, length(y))
    

    Here is a good explanation for those who are interested: http://rfunction.com/archives/223

    0 讨论(0)
  • 2021-01-05 18:35

    Your offset term has to be a variable, like x and y, not a numeric constant. So you need to create a column in your dataset with the appropriate values.

    dat$o <- 283.56
    lm(y ~ I(x - x0) - 1, data=dat, offset=o)
    
    0 讨论(0)
提交回复
热议问题