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

前端 未结 3 1697
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:43

    I think you just have to use the algebra to invert y=a+b*x to x=(y-a)/b:

    cc <- coef(model)
    (xnew <- (ynew-cc[1])/cc[2])
    # [1]  31.43007 104.76689 178.10372
    
    plot(x,y
    abline(model)
    points(xnew,ynew,col=2)
    

    Looking at your 'data' here, I think a nonlinear regression might be better ...

    enter image description here

提交回复
热议问题