fda 패키지를 사용하여 "curve"라는 fd 개체를 만들었습니다.
splinebasis = create.bspline.basis(rangeval = c(0,100),
nbasis = 23,
norder = 4)
curve = smooth.basis(x, y, splinebasis)$fd
이 시점에서 다음 명령을 통해 쉽게 fd 객체를 그릴 수 있습니다.
plot(curve)
좋은 결과를 얻고 있습니다.
내가하고 싶은 것은 ggplot2 패키지를 사용하여 객체를 그리는 것이지만, 불행히도 ggplot2 st를 코딩하는 방법에 대한 단서가 없습니다. 이는 기저와 계수를 사용하여 연속 곡선을 반환합니다 *.
다음은 패키지 predict
에서 사용하는 간단한 솔루션 fda
입니다.
library(fda)
set.seed(1)
x <- 0:100
y <- cumsum(rnorm(101))
splinebasis <- create.bspline.basis(rangeval = c(0,100),
nbasis = 23,
norder = 4)
curve <- smooth.basis(x, y, splinebasis)
# Plot using base graphic engine
plot(curve$fd)
# Plot using ggplot2
library(ggplot2)
xx <- seq(0,100,0.1)
df <- data.frame(x=xx, yhat = predict(curve, newdata=xx))
ggplot(data=df, aes(x=x, y=yhat)) +
geom_line() +
geom_hline(aes(yintercept=0), linetype=2) +
labs(x="time", y="value") +
theme_bw()
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다