我正在研究一个关于年度作物产量与天气参数之间关系的回归模型。从1960年到现在的作物产量数据显示出明显的上升趋势。许多研究表明,这可能是由于技术进步。为了使回归模型更加可靠,可以采用一种去趋势方法。
任何从事同一主题工作的人都知道如何降低作物产量?我尝试过从pracma包中提取下降趋势函数,但它似乎不起作用。
以1960年至1980年两个县的玉米产量数据为例,
>view(corn)
year county1 county2
1960 50 52
1961 69 79
1962 75 84
1963 77 87
1964 60 81
1965 81 99
1966 67 83
1967 96 103
1968 81 104
1969 81 84
1970 51 82
1971 91 115
1972 100 118
1973 102 106
1974 69 96
1975 96 107
1976 103 95
1977 98 62
1978 106 105
1979 111 136
1980 95 97有人知道怎么做这种不流行的事吗?非常感谢!
发布于 2017-08-30 04:02:17
这里有一个解决方案,它使用了实践中的递减函数。它在以特定方式调整数据格式之后工作。
require(pracma)
#Create data frame with country data:
df <- data.frame(
"country1"=c(50,69,75,77,60,81,67,96,81,81,51,91,100,102,69,96,
103,98,106,111,95),
"country2"=c(52,79,84,87,81,99,83,103,104,84,82,115,118,106,96,
107,95,62,105,136,97))
#Transpose data frame, making a matrix in the process:
df <- t(df)
#Add dates as column names:
colnames(df) <- c(1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,
1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980)
#Apply detrend:
data.detrend <- detrend(df, tt = 'linear')
#Apply time series:
data.detrend <- ts(as.numeric(data.detrend),
start=c(1960,1), frequency=2)
str(data.detrend) #check date range
#Plot:
plot.ts(data.detrend)

https://stackoverflow.com/questions/45951234
复制相似问题