我在应用惩罚复合链接模型(PCLM)函数时遇到了麻烦,该函数只适用于向量。我使用pclm函数从5岁年龄组的人口数据中生成单年龄(syoa)人口数据。
可以按照作者在https://github.com/mpascariu/ungroup上给出的说明安装pclm()。
函数的用法:
pclm(x, y, nlast,control = list())
-x: vector of the cumulative sum points of the sequence in y.
-y: vector of values to be ungrouped.
-nlast: Length of the last interval.
-control: List with additional parameters.这是我的训练数据集:
data<-data.frame(
GEOID= c(1,2),
name= c("A","B"),
"Under 5 years"= c(17,20),
"5-9 years"= c(82,90),
"10-14 years"= c(18, 22),
"15-19 years"= c(90,88),
"20-24 years"= c(98, 100),
check.names=FALSE)
#generating a data.frame storing the fitted values from the pclm for the first row: GEOID=1.
#using the values directly
syoa <- data.frame(fitted(pclm(x=c(0, 5, 10, 15, 20), y=c(17,82,18,90,98), nlast=5, control = list(lambda = .1, deg = 3, kr = 1))))
#or referring to the vector by its rows and columns
syoa <- data.frame(fitted(pclm(x=c(0, 5, 10, 15, 20), y=c(data[1,3:7]), nlast=5, control = list(lambda = .1, deg = 3, kr = 1))))因为我的数据有很多观察值,所以我想对列3-7: data,3:7的所有行应用pclm()函数。
apply(data[3:7], 1, pclm(x=c(0, 5, 10, 15, 20), y=c(data[,3:7]), nlast=5, control = list(lambda = .1, deg = 3, kr = 1))) 但它不工作,并给出以下错误消息:
Error in eval(substitute(expr), data, enclos = parent.frame()) :
(list) object cannot be coerced to type 'double'我不知道这个问题与apply()或pclm ()函数有关。有人能帮上忙吗?谢谢。
https://stackoverflow.com/questions/51452292
复制相似问题