R 如何将cobs样条曲线包生成的数据显示为ggplot2 wt1
如果您在问题中陈述错误,R 如何将cobs样条曲线包生成的数据显示为ggplot2 wt1,r,ggplot2,R,Ggplot2,如果您在问题中陈述错误,predict不会返回点x和y,它会返回一个两列矩阵,其中第二列包含拟合值。 我将使用help('cobs')的第一个示例中创建的数据 我从未使用过cobs,但使用函数coef可以从wt1 wt1 <- cobs(x, y, constraint= "increase", lambda = 1, pointwise = con) library(cobs) set.seed(1234) # Make the results reproducible x
predict
不会返回点x
和y
,它会返回一个两列矩阵,其中第二列包含拟合值。我将使用
help('cobs')
的第一个示例中创建的数据
我从未使用过cobs,但使用函数
coef
可以从wt1
wt1 <- cobs(x, y, constraint= "increase", lambda = 1, pointwise = con)
library(cobs)
set.seed(1234) # Make the results reproducible
x <- seq(-1, 3, , 150)
y <- (f.true <- pnorm(2*x)) + rnorm(150)/10
con <- rbind(c( 1,min(x),0), # f(min(x)) >= 0
c(-1,max(x),1), # f(max(x)) <= 1
c(0, 0, 0.5))# f(0) = 0.5
wt1 <- cobs(x,y, constraint= "increase", lambda = 1, pointwise = con)
fit <- predict(wt1, x)[, 'fit']
df1 <- data.frame(x, y, fit)
ggplot(df1, aes(x, y)) +
geom_point() +
geom_line(aes(y = fit), colour = 'red')