首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R:应用pclm函数

R:应用pclm函数
EN

Stack Overflow用户
提问于 2018-07-21 10:25:23
回答 0查看 81关注 0票数 0

我在应用惩罚复合链接模型(PCLM)函数时遇到了麻烦,该函数只适用于向量。我使用pclm函数从5岁年龄组的人口数据中生成单年龄(syoa)人口数据。

可以按照作者在https://github.com/mpascariu/ungroup上给出的说明安装pclm()

函数的用法:

代码语言:javascript
复制
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.

这是我的训练数据集:

代码语言:javascript
复制
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()函数。

代码语言:javascript
复制
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))) 

但它不工作,并给出以下错误消息:

代码语言:javascript
复制
Error in eval(substitute(expr), data, enclos = parent.frame()) : 
  (list) object cannot be coerced to type 'double'

我不知道这个问题与apply()pclm ()函数有关。有人能帮上忙吗?谢谢。

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51452292

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档