楼主: zilahu
4604 5

[问答] 如何用R模拟完全随机缺失数据? [推广有奖]

  • 0关注
  • 0粉丝

高中生

10%

还不是VIP/贵宾

-

威望
0
论坛币
8 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
246 点
帖子
8
精华
0
在线时间
23 小时
注册时间
2014-5-2
最后登录
2018-11-10

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
> #####MCAR
> library(simFrame)
Loading required package: Rcpp
Loading required package: lattice
Loading required package: parallel
Warning messages:
1: package ‘simFrame’ was built under R version 3.4.4
2: package ‘Rcpp’ was built under R version 3.4.4
> bar<-rnorm(100,10,1)    #situmlation data
> nc<-NAControl(NArate=0.2)   #set missing rate
> x<-setNA(bar,nc)    #insert into missing data from bar
Error in (function (classes, fdef, mtable)  :
  unable to find an inherited method for function ‘setNA’ for signature ‘"numeric", "NAControl"’

如上,本人想用r中的simFrame包来模拟缺失,完全随机缺失MCAR,到缺失比例这一步还是可以的,可是下面这一句报错,不知道该如何解决?
> x<-setNA(bar,nc)    #insert into missing data from bar
Error in (function (classes, fdef, mtable)  :
  unable to find an inherited method for function ‘setNA’ for signature ‘"numeric", "NAControl"’
本人还处于入门级别的菜鸟,请各位大神多多指教。

或者有没有其他方法可以模拟数据的缺失,MCAR,我的研究是先生成一个完整矩阵,再设置缺失比例,生成缺失矩阵,之后进行分析。
求帮助!



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:缺失数据 如何用 required Parallel messages 缺失数据 模拟程序 r语言入门

沙发
hifinecon 发表于 2018-6-5 19:38:07 |只看作者 |坛友微信交流群
I think your NAControl function lacks of a target.
已有 1 人评分论坛币 收起 理由
cheetahfly + 10 热心帮助其他会员

总评分: 论坛币 + 10   查看全部评分

使用道具

藤椅
zilahu 发表于 2018-6-6 20:42:42 |只看作者 |坛友微信交流群
hifinecon 发表于 2018-6-5 19:38
I think your NAControl function lacks of a target.
谢谢~
我试一下~

使用道具

板凳
hifinecon 发表于 2018-6-6 21:50:06 |只看作者 |坛友微信交流群
good luck!

使用道具

报纸
ccs0531 发表于 2018-6-8 09:09:57 |只看作者 |坛友微信交流群
hifinecon 发表于 2018-6-5 19:38
I think your NAControl function lacks of a target.
bar2<-as.data.frame(bar) 然后x<-setNA(bar2,nc)

使用道具

地板
ccs0531 发表于 2018-6-8 09:10:36 |只看作者 |坛友微信交流群
setNA(x, control, ...)

## S4 method for signature 'data.frame,NAControl'
setNA(x, control, i)
Arguments

x       
the data in which missing values should be inserted.
control       
a control object inheriting from the virtual class "VirtualNAControl" or a character string specifying such a control class (the default being "NAControl").
i       
an integer giving the element or row of the slot NArate of control to be used as missing value rate(s).
...       
if control is a character string or missing, the slots of the control object may be supplied as additional arguments. See "NAControl" for details on the slots.

Methods

x = "data.frame", control = "character"
set missing values using a control class specified by the character string control. The slots of the control object may be supplied as additional arguments.

x = "data.frame", control = "missing"
set missing values using a control object of class "NAControl". Its slots may be supplied as additional arguments.

x = "data.frame", control = "NAControl"
set missing values as defined by the control object control.

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-26 22:14