Plot the observed and fitted values from a linear regression using xyplot() from the lattice package

后端 未结 2 717
北恋
北恋 2021-02-04 20:44

I can create simple graphs. I would like to have observed and predicted values (from a linear regression) on the same graph. I am plotting say Yvariable vs Xv

2条回答
  •  广开言路
    2021-02-04 21:14

    Another option is to use panel.lmlineq from latticeExtra.

    library(latticeExtra)
    set.seed(0)
    xsim <- rnorm(50, mean = 3)
    ysim <- (0 + 2 * xsim) * (1 + rnorm(50, sd = 0.3))
    
    ## basic use as a panel function
    xyplot(ysim ~ xsim, panel = function(x, y, ...) {
      panel.xyplot(x, y, ...)
      panel.lmlineq(x, y, adj = c(1,0), lty = 1,xol.text='red',
                    col.line = "blue", digits = 1,r.squared =TRUE)
    })
    

    enter image description here

提交回复
热议问题