基于R中的其他变量模拟变量
我希望模拟一组与模拟数值变量相关的分类变量。更具体地说,我具有可变的age
,其定义为:age< - rnorm(n = 1000,平均= 35,sd = 9)
,我希望模拟另一个变量类
,其中更高的年龄使更高的类。谁能向我指向正确的方向?提前致谢!
I wish to simulate a set of categorical variables which correlates with a simulated numerical variable. More specifically, I have variable the age
which is defined like: age <- rnorm(n=1000, mean=35, sd =9)
and I wish to simulate another variables class
in which higher age makes for higher class. Can anyone point me in the right direction? Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道的是,如果
a
与b
相关,则表示a
和b
是线性相关的。因此,a
可以用b
的线性函数表示。为了生成随机变量,应添加随机噪声。这是这样做的一种方法:
What I understand is that if
a
correlates withb
, it meansa
andb
are linearly related. So,a
can be represented by a linear function ofb
. To generate random variables, a random noise should be added.Here is one way of doing that: