Plot 3D plane (true regression surface)

后端 未结 3 2037
天命终不由人
天命终不由人 2020-12-09 07:06

I\'m trying to simulate some data (x1 and x2 - my explanatory variables), calculate y using a specified function + random noise and plot the resulting observations AND the t

3条回答
  •  有刺的猬
    2020-12-09 07:33

    Apologies: ( I didn't read the question very carefllly and now see that I rushed into estimation when you wanted to plot the Truth.)

    Here's an approach to estimation followed by surface plotting using loess:

    mod2 <- loess(y~x1+x2)
    grd<- data.frame(x1=seq(range(x1)[1],range(x1)[2],len=20), 
                     x2=seq(range(x2)[1],range(x2)[2],len=20))
    grd$pred <- predict(mod2, newdata=grd)
    grd <- grd[order(grd$x1,grd$x2),]
    x1 <- unique(grd$x1)
    x2 <- unique(grd$x2)   # shouldn't have used y
    surface3d(x1, x2, z=matrix(grd$pred,length(x1),length(x2)) )
    

    Points and loess fit

提交回复
热议问题