Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R:从smooth.spline到插值到更精细时间尺度的预测_R - Fatal编程技术网

R:从smooth.spline到插值到更精细时间尺度的预测

R:从smooth.spline到插值到更精细时间尺度的预测,r,R,典型问题:来自不同仪器的数据记录在不同的时间尺度上。这里我有每小时的环境数据(envdat),我想在我的响应数据(respdat)中添加一列包含环境数据。但是,响应数据每秒钟有一个点,但它是高于阈值的电压的子集(缺少点)。我的目标是根据环境数据拟合一条曲线(类似于正弦波),并对每个响应观测值进行插值。见下例: envdat=structure(list(date.time = structure(c(1369552133, 1369555733, 1369559333, 1369562933,

典型问题:来自不同仪器的数据记录在不同的时间尺度上。这里我有每小时的环境数据(envdat),我想在我的响应数据(respdat)中添加一列包含环境数据。但是,响应数据每秒钟有一个点,但它是高于阈值的电压的子集(缺少点)。我的目标是根据环境数据拟合一条曲线(类似于正弦波),并对每个响应观测值进行插值。见下例:

envdat=structure(list(date.time = structure(c(1369552133, 1369555733, 
1369559333, 1369562933, 1369566533, 1369570133, 1369573733, 1369577333, 
1369580933, 1369584533, 1369588133, 1369591733, 1369595333, 1369598933, 
1369602533, 1369606133, 1369609733, 1369613333, 1369616933, 1369620533, 
1369624133, 1369627733, 1369631333, 1369634933), class = c("POSIXct", 
"POSIXt"), tzone = ""), cool.C = c(9.866, 9.077, 9.077, 6.573, 
6.573, 6.573, 9.669, 9.472, 9.373, 11.334, 11.334, 11.236, 13.75, 
13.942, 13.076, 16.713, 16.808, 16.808, 14.23, 14.325, 14.421, 
11.625, 11.625, 12.207)), .Names = c("time", "temp"), row.names = 63:86, class =     "data.frame")
plot(data$time,data$temp,type="b")
myspline=smooth.spline(data$time,data$temp,spar=.5)
lines(myspline,col="red")
####
respdat=structure(list(time = structure(c(1369606346, 1369606356, 
1369606359, 1369606360, 1369606361, 1369606362, 1369606363, 1369606364, 
1369606365, 1369606366, 1369606367, 1369606368, 1369606369, 1369606370, 
1369606371, 1369606372, 1369606373, 1369606374, 1369606375, 1369606376, 
1369606377, 1369606378, 1369606379, 1369606380, 1369606381), class = c("POSIXct", 
"POSIXt"), tzone = ""), volts = c(2.511094, 2.509647, 2.524574, 
2.954419, 2.756494, 2.59868, 2.94975, 2.87183, 2.846382, 2.788386, 
3.144585, 3.099345, 2.931733, 3.032537, 2.870383, 2.869857, 2.841319, 
2.886822, 2.750839, 3.109142, 3.017413, 3.1194, 2.909508, 2.899776, 
2.903129)), .Names = c("time", "volts"), row.names = c(4036L, 
4046L, 4049L, 4050L, 4051L, 4052L, 4053L, 4054L, 4055L, 4056L, 
4057L, 4058L, 4059L, 4060L, 4061L, 4062L, 4063L, 4064L, 4065L, 
4066L, 4067L, 4068L, 4069L, 4070L, 4071L), class = "data.frame")
print(respdat)
我的做法是:

test=predict(myspline,respdat$time)

这将返回一个错误。欢迎指导。

这里提供了一种将环境小时数据插值为秒数据的方法

library(xts)
## you create the xts object
env.xts <- xts(envdat$temp,envdat$time)
## new index to be used 
new.index <- 
  seq(min(index(env.xts)),max(index(env.xts)), by=as.difftime(1,units='secs'))
## linear approx
na.spline(merge(env.xts,xts(NULL,new.index)))
库(xts)
##创建xts对象
环境xts