How to predict x values from a linear model (lm)

前端 未结 3 1692
Happy的楠姐
Happy的楠姐 2021-02-08 12:23

I have this data set:

x <- c(0, 40, 80, 120, 160, 200)
y <- c(6.52, 5.10, 4.43, 3.99, 3.75, 3.60)

I calculated a linear model using

3条回答
  •  礼貌的吻别
    2021-02-08 12:47

    Since this is a typical problem in chemistry (predict values from a calibration), package chemCal provides inverse.predict. However, this function is limited to "univariate model object[s] of class lm or rlm with model formula y ~ x or y ~ x - 1."

    x <- c(0, 40, 80, 120, 160, 200)
    y <- c(6.52, 5.10, 4.43, 3.99, 3.75, 3.60)
    plot(x,y)
    model <- lm(y ~ x)
    abline(model)
    require(chemCal)
    ynew <- c(5.5, 4.5, 3.5)
    xpred<-t(sapply(ynew,function(y) inverse.predict(model,y)[1:2]))
    #  Prediction Standard Error
    #[1,] 31.43007   -38.97289     
    #[2,] 104.7669   -36.45131     
    #[3,] 178.1037   -39.69539
    points(xpred[,1],ynew,col="red")
    

    Warning: This function is quite slow and not suitable, if you need to inverse.predict a large number of values.

    If I remember correctly, the neg. SEs occur because the function expects the slope to be always positive. Absolute values of SE should still be correct.

提交回复
热议问题