gpt4 book ai didi

r - R 样条插值

转载 作者:行者123 更新时间:2023-12-04 11:05:02 25 4
gpt4 key购买 nike

我想对人口数据执行(三次)样条插值,以将年度数据“转换”为季度数据。我知道这样做有很多缺陷,但我需要这样做。

这是我的代码示例(使用通用输入数据):

#--------------spline interpolation

x = c(1973:2014)
population = seq(500000, 600000, length.out = 42)
list = spline(x, population, n = 4*length(x), method = "fmm",
xmin = min(x), xmax = max(x), ties = mean)

x_spline = list$x
pop_spline = list$y

我如何定义样条是“每季度”计算的,换句话说,在 1973.25、1973.5、1973.75、1974 等?很抱歉不是统计专家:将年度数据“转换”为季度数据的最佳方法是什么:“fmm”、“natural”、“periodic”、“monoH.FC”或“hyman”?假设人口增长在一年中均匀分布。

最好的问候,并提前致谢!

最佳答案

为什么不使用 splinefun :

func = splinefun(x=x, y=population, method="fmm",  ties = mean)

然后你定义你想要的预测点:
func(seq(1973, 2014, 0.25))

关于r - R 样条插值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28216277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com