Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 用晶格和量子图绘制多重分位数回归线_R_Plot_Lattice_Quantreg - Fatal编程技术网

R 用晶格和量子图绘制多重分位数回归线

R 用晶格和量子图绘制多重分位数回归线,r,plot,lattice,quantreg,R,Plot,Lattice,Quantreg,我想绘制几个分位数回归线quantreg包,如下所示: library(quantreg) data(engel) attach(engel) plot(income, foodexp, cex = 0.25, type = "n", xlab = "Household Income", ylab = "Food Expenditure") points(income, foodexp, cex = 0.5, col = "blue") abline(rq(foodexp

我想绘制几个分位数回归线quantreg包,如下所示:

 library(quantreg)
 data(engel)
 attach(engel)
 plot(income, foodexp, cex = 0.25, type = "n",
      xlab = "Household Income", ylab = "Food Expenditure")
 points(income, foodexp, cex = 0.5, col = "blue")
 abline(rq(foodexp ~ income, tau = 0.5), col = "blue")
 abline(lm(foodexp ~ income), lty = 2, col = "red")
 taus <- c(0.05, 0.1, 0.25, 0.75, 0.9, 0.95)
 for (i in 1:length(taus)) {
   abline(rq(foodexp ~ income, tau = taus[i]),
          col = "gray")
 }
 detach(engel)
使用lattice,您应该只在panel函数中使用y和x

xyplot(foodexp~income , data =engel, 
       type = c("g"),
       auto.key=list(x=.8,y=.35,cex=.8,cex.title=.8, title="", points=TRUE), 
       scales=list(tck=-1),ylab=list("Food Expenditure",font=3),
       xlab=list("Household Income",font=3),
       panel=function(x,y,...){
         panel.xyplot(x,y)
         panel.grid()
         panel.abline(rq(y ~ x, tau = 0.5))
         panel.points(x, y, cex = 0.5, col = "blue")
         panel.abline(rq(y ~ x, tau = 0.5), col = "blue")
         panel.abline(lm(y ~ x), lty = 2, col = "red")
         taus <- c(0.05, 0.1, 0.25, 0.75, 0.9, 0.95)
         for (i in 1:length(taus)) {
           panel.abline(rq(y ~ x, tau = taus[i]),
                  col = "gray")
         }

       }
)
使用lattice,您应该只在panel函数中使用y和x

xyplot(foodexp~income , data =engel, 
       type = c("g"),
       auto.key=list(x=.8,y=.35,cex=.8,cex.title=.8, title="", points=TRUE), 
       scales=list(tck=-1),ylab=list("Food Expenditure",font=3),
       xlab=list("Household Income",font=3),
       panel=function(x,y,...){
         panel.xyplot(x,y)
         panel.grid()
         panel.abline(rq(y ~ x, tau = 0.5))
         panel.points(x, y, cex = 0.5, col = "blue")
         panel.abline(rq(y ~ x, tau = 0.5), col = "blue")
         panel.abline(lm(y ~ x), lty = 2, col = "red")
         taus <- c(0.05, 0.1, 0.25, 0.75, 0.9, 0.95)
         for (i in 1:length(taus)) {
           panel.abline(rq(y ~ x, tau = taus[i]),
                  col = "gray")
         }

       }
)