【发布时间】:2015-05-01 07:10:18
【问题描述】:
我正在分析长期定期收集的气象数据(大部分数据每 15 到 60 分钟一次)。温度和太阳辐射影响的其他措施每天都有周期。如果辐射没有被云层阻挡,我试图描述一年中任何一天的平均太阳辐射暴露量。我可以访问多年的数据,并且可以根据一年中的日期平均我放入 R 中的任何数据。为了描述晴天的平均辐射量,在我做平均值之前需要丢弃一些数据。
显然我没有发布该图形的声誉,但无云日的辐射模式图具有抛物线形状。阴天可以通过具有多个峰值的曲线来识别。二次回归的R^2值可以用来区分这两种天数。
(编辑——所有辐射数据和日期/时间时间都报告在一个文本文件的两列中。我已按日期分隔下面的数据,以便任何读者轻松查看我正在尝试分析的模式,并且因为我不知道共享数据和显示模式的更复杂的方法。)
# The following vectors contain the dates and times of the readings, and the
# radiation recorded.
DateTime1<-c("13/10/23 07:00", "13/10/23 08:00", "13/10/23 09:00", "13/10/23 10:00", "13/10/23 11:00", "13/10/23 12:00", "13/10/23 13:00", "13/10/23 14:00", "13/10/23 15:00", "13/10/23 16:00", "13/10/23 17:00", "13/10/23 18:00", "13/10/23 19:00")
Sol.Rad1<-c(0, 68.78761823, 214.961307, 369.733448, 498.7102322, 576.0963027, 601.8916595, 541.7024936, 447.1195185, 352.5365434, 189.1659501, 8.598452279, 0)
DateTime2<-c("13/10/24 07:00", "13/10/24 08:00", "13/10/24 09:00", "13/10/24 10:00", "13/10/24 11:00", "13/10/24 12:00", "13/10/24 13:00", "13/10/24 14:00", "13/10/24 15:00", "13/10/24 16:00", "13/10/24 17:00", "13/10/24 18:00", "13/10/24 19:00")
Sol.Rad2<-c(0, 68.78761823, 214.961307, 369.733448, 498.7102322, 309.544282, 576.0963027, 386.9303525, 464.316423, 326.7411866, 167.6698194, 8.598452279, 0)
# The vector "Centered" is used to represent the time of day with the
# potential peak of radiation as the centered zero value. This vector allows
# for the quadratic regressions.
Centered<-c( -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6)
# Combine the vectors into data frames; one for each day.
day1<-data.frame(DateTime1,Centered,Sol.Rad1)
day2<-data.frame(DateTime2,Centered,Sol.Rad2)
# Plotting day1 shows the parabolic shape of a cloudless day
plot(day1$Sol.Rad1 ~ day1$Centered)
# Plotting day2 shows differences in the curve (two additional peaks) due to
# cloud cover.
plot(day2$Sol.Rad2 ~ day2$Centered)
# The R^2 values from a quadratic regression of day1 are close to 0.93.
qr1<- lm(day1$Sol.Rad ~ poly(day1$Centered, 2, raw=TRUE))
summary(qr1)
# While the R^2 values from day2 are less than 0.86.
qr2<- lm(day2$Sol.Rad ~ poly(day2$Centered, 2, raw=TRUE))
summary(qr2)
如果我能找到一种方法在更大的数据集中每天重复此过程,则可以使用 R^2 的差异来区分阴天和晴天。
有没有一种方法可以从单个数据框中进行多次二次回归,其中日期和时间或所有日期的辐射读数都在单个列中报告。
理想情况下,我希望得到一个包含两列的表格。一列将包含一年中的某一天,第二列将包含来自二次回归分析的 R^2 值。我认为 Multiple R^2 或 Adjusted R^2 都可以工作(但我不太了解 R^2 的两个版本之间的区别,我无法被说服使用其中一个来代替另一个。)
我不知道如何仅报告二次回归分析中的 R^2 值,或者如何将二次回归重复次数与我分析的数据天数一样多。我可能会查看 10 年的数据,因此能够在单个表格中分析和报告分析结果将是对我可以使用哪些日期的数据进行排序的绝佳方式。
【问题讨论】:
标签: r datetime iteration non-linear-regression