从 R 中列表的元素估计概率 [英] Estimate a probability from elements of a list in R
问题描述
我在 R 中有一个包含 100,000 个 T 模拟数的列表(最小值:1.5,最大值 88.8),我想计算 T 介于 10 和 50 之间的概率.
I have a list of 100,000 simulated numbers of T in R (min: 1.5, max 88.8) and I want to calculate the probability of T being between 10 and 50.
我对 T 的 100,000 个数字求和,其中 T 是 t(y) %*% M %*% y
其中 M
是常数值和 y 的 8x8 矩阵是一个 8x1 矩阵.i
-th 行中的元素如果 y,等于: a_i + b_i
其中 a 是常量向量,b 是其元素跟随 normal (0,sd=2)
分布(每个元素是 N(0,2)
的不同模拟数)
I sumulated 100,000 numbers of T, where T is t(y) %*% M %*% y
where M
is a 8x8 matrix of constant values and y is a 8x1 matrix. The element in the i
-th row if y, is equal to: a_i + b_i
where a is a vector of constants and b is a vector whose elements follow a normal (0,sd=2)
distribution (each element is a different simulated number of N(0,2)
)
推荐答案
是在向量中还是在列表中?如果它是向量,则以下应该有效.如果它在列表中,您可以使用 unlist() 将其转换为向量.
Is it in a vector or a list? If it's a vector, the following should work. If it's in a list, you may use unlist() to convert it to a vector.
mylist <- runif(100000,1.5,88.8) #this is just to generate a random number vector
length(which(mylist>=10 & mylist<=50))/length(mylist)
这篇关于从 R 中列表的元素估计概率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!