2
我在河中使用loess()
和predict()
一些麻煩,我用下面的代碼來模擬數據的黃土線:擬合R中
Overall=0.6
RR=1.1
Noise=0.05
x=seq(from=0.01, to=10, by=0.01)
logRR=log(RR)
logBeta0=log(Overall)
linear.pred = logBeta0 + (logRR*x) + rnorm(length(x), 0, Noise*sqrt(x))
linear.pred.high = logBeta0 + (logRR*15) + rnorm(length(x), 0, Noise/5)
PoissonRate <- function (x) ifelse(x<=9, exp(linear.pred), exp(linear.pred.high))
xyplot(PoissonRate(x)~x) #the shape of the 'raw' data
loess_fit <- loess(x~PoissonRate(x))
lines(predict(loess_fit), col = "black")
道歉,但我不能工作了如何安裝一張圖片來展示這看起來像什麼!
代碼的最後兩行最終只是添加一個隨機的黑線半落圖,雖然當我以前使用過不同的(非常相似)的數據此命令,它似乎正常工作。我錯過了什麼?!任何幫助將是巨大的,謝謝:)
您不能使用'lines'將數據添加到格圖形圖。見'lline()'。您正在繪製數據。如果模型是'x〜PoissonRate(x)',那麼你在'xyplot'中繪製'x〜PoissonRate(x)'。在'llines()'中,你需要給出'x'和'y'參數 - 但是你只能給出'predict()'的輸出,一個向量...... – 2013-03-27 17:43:51