How do I fit confidence bands to a custom function in R? -


i'm beginning in r , struggling add confidence intervals function defined. have seen plenty of examples linear models , know ggplot2 can functions. however, fitting bands custom function proving tricky. below have data , function:

data<-matrix(c(0.08, 0.1, 0.12, 0.13, 0.49, 0.11, 0.12, 0.15, 0.22, 0.47, 7, 8 , 9, 21, 30, 3, 8, 13, 15, 17),ncol=2) mycurve<-function(x){a+(b*log(x))} plot(data) curve(mycurve,add=t) 

this 1 example, have few more datasets , custom curve functions need in addition one. appreciate if suggest way of doing using either plot or ggplot (e.g. maybe using geom_ribbon?). have spent quite while searching stackoverflow, haven't yet found solution. if there one, perhaps point me it...

thanks in advance!

edit: sorry, forgot add parameters a , b. are:

a<-31 b<-9 

edit 2: have tried suggestions @ben bolker , @marcin kosinski use geom_smooth , plotted along custom curve:

data<-as.data.frame(data) #so ggplot can use it ggplot(data,aes(v1,v2))+geom_smooth(method="lm",formula=y~1+log(x))+ geom_point()+stat_function(fun=mycurve,color="red")

the result is: enter image description here

the red curve custom function need use. problem need geom_smooth using function (or alternative approach yield same results).

thanks far!

edit3: covariance matrix is:

29.3897 14.5805
14.5805 8.01302

you have not said , b come from. not clear doing statistics confidence bands make sense. if , b fixed/known constants there no need confidence bands, or confidence bands have 0 width , same prediction line.

if , b estimates of parameter there possibility of confidence bands, correct values depend on how , b calculated.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -