我想用公式>r²=(x-h)2 +(y-k)2來計算半徑的預測間隔。圓的半徑,x,y,是高斯座標,h,k,標記擬合圓的中心。如何計算擬合R的圓的預測間隔
# data
x <- c(1,2.2,1,2.5,1.5,0.5,1.7)
y <- c(1,1,3,2.5,4,1.7,0.8)
# using nls.lm from minpack.lm (minimising the sum of squared residuals)
library(minpack.lm)
residFun <- function(par,x,y) {
res <- sqrt((x-par$h)^2+(y-par$k)^2)-par$r
return(res)
}
parStart <- list("h" = 1.5, "k" = 2.5, "r" = 1.7)
out <- nls.lm(par = parStart, x = x, y = y, lower =NULL, upper = NULL, residFun)
的問題是,predict()
不nls.lm工作,所以我試圖用計算的nlsLM圈配合。 (我可以用手工計算,但有麻煩創建我Designmatrix).`
原來這就是我想未來:
dat = list("x" = x,"y" = y)
out1 <- nlsLM(y ~ sqrt(-(x-h)^2+r^2)+k, start = parStart)
導致:
Error in stats:::nlsModel(formula, mf, start, wts) :
singular gradient matrix at initial parameter estimates
問題1A: nlsLM()
如何使用圓圈擬合? (優點在於,通用predict()
可 問題1B:我如何得到預測區間爲我的圈子適合從線性迴歸
實例(這是我想要的效果圈迴歸)
attach(faithful)
eruption.lm = lm(eruptions ~ waiting)
newdata = data.frame(waiting=seq(45,90, length = 272))
# confidence interval
conf <- predict(eruption.lm, newdata, interval="confidence")
# prediction interval
pred <- predict(eruption.lm, newdata, interval="predict")
# plot of the data [1], the regression line [1], confidence interval [2], and prediction interval [3]
plot(eruptions ~ waiting)
lines(conf[,1] ~ newdata$waiting, col = "black") # [1]
lines(conf[,2] ~ newdata$waiting, col = "red") # [2]
lines(conf[,3] ~ newdata$waiting, col = "red") # [2]
lines(pred[,2] ~ newdata$waiting, col = "blue") # [3]
lines(pred[,3] ~ newdata$waiting, col = "blue") # [3]
親切的問候
摘要編輯的:
EDIT1:在nlsLM重排式,但參數(H,K,R)的結果現在是在出並OUT1不同...
編輯2:增加了兩個維基百科鏈接,用於澄清puprose上使用的術語:(c.f.下文)
EDIT3:問題(S)的一些改述
Edit4:增加了線性迴歸的工作示例
找到h,k和r不是問題。這已經是海報代碼中名爲「out」的結果的一部分。 –