Can I export the result from a loess regression out of R?

萝らか妹 提交于 2020-01-06 04:05:10

问题


I have performed a loess regression on some data and plotted it. The problem is I'd like to export the black line and light red line (see figure) into excel. Is it possible?

Clarification:

I want to export the underlying data from the loess regression not the graph.

Code used to calculate it:

ggplot(data, aes(x=bigangle, y=meanz, colour=treatment)) + 
  geom_point(data=df, aes(y = X2/median(df$X2), x=X8),color="red",alpha=.6) +
  geom_smooth(data=df, aes(y = X2/median(df$X2),x=X8),fill="red", colour="black", size=1,alpha=0.4)+
  geom_point(position=position_dodge(0.1),aes(shape=treatment),   # Shape depends on cond
             size = 4,colour="black",fill="black") 

回答1:


I am not sure what loess function ggplot2 uses, but here is one way to extract a loess object to graph in Excel:

# fake data
myData <- data.frame("x"=1:100, "y"=rnorm(100))
# loess object
my.loess <- loess(y~x, data=temp)
# get SE
myPred <- predict(my.loess, se=T)
my.output <- data.frame("fitted"=myPred$fit, "SE"=myPred$se.fit)

# write out data
write.csv(my.output, file=<path/filename>.csv)


来源:https://stackoverflow.com/questions/36987104/can-i-export-the-result-from-a-loess-regression-out-of-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!