在 R 编程中创建 t 分布内的随机数字序列 – rt()函数
R 语言中的rt()
函数用于从学生 t 分布中创建随机值序列。
Syntax: rt(n, df, ncp)
Parameters:
n: Number of observations
df: Degree of Freedom
ncp: Numeric vector of non-centrality parameters.
示例 1:
# R Program to create random sequence
# from t distribution
# Calling rt() Function
rt(15, 2)
rt(15, 1)
输出:
[1] 2.09851925 -1.76883434 -0.56019367 0.23263458 1.02778818 -0.82274015
[7] -1.33110401 4.19230931 0.80622707 0.02468189 -4.00469465 0.02974788
[13] 1.28649412 -0.19235704 0.21665196
[1] 2.21010764 -11.70663704 -1.00452125 2.07828752 1.95781361
[6] -0.53603661 0.02068073 -1.32464307 -49.93080321 0.82594818
[11] -0.46109805 -0.18965787 0.60498953 -0.44659619 -0.08968020
示例 2:
# R Program to create random sequence
# from t distribution
# Calling rt() Function
rt(5, 1, 1:5 * 5)
rt(5, 2, 1:10)
输出:
[1] 23.88663 20.26813 62.95437 14.59003 20.58296
[1] 0.1745755 4.5298859 1.1175184 7.4660938 45.1399588