2015-04-06 75 views
1

我有一个数据样本 (比如说1.9 4.8 3.9 4.7 2.3 4.6 3.9)如何使用统计

我要分发的钟形曲线的数据,并给予之间的收视率通常分布数据1到5.如何使用统计数据。

(最高的20%将被评为5,然后4等)

+0

参见[本SO文章( http://stackoverflow.com/questions/19343133/setting-upper-and-lower-limits-in-rnorm)这似乎处理您的问题。 – 2015-04-06 05:42:26

+0

你基本上想要使用'rnorm',但限制上限值和下限值。 – 2015-04-06 05:42:46

+0

您的评分​​将构成什么? – 2015-04-06 06:03:34

回答

3

这里是你的问题的第一部分

x <- c(1.9,4.8,3.9,4.7,2.3,4.6,3.9) 

sigma <- sd(x) # 1.175747 
mu <- mean(x) # 3.728571 

curve((1/(sigma*sqrt(2*pi)))*exp(-((x-mu)^2)/(2*sigma^2)),xlim=c(-1,9),ylab="density") 

y <- (1/(sigma*sqrt(2*pi)))*exp(-((x-mu)^2)/(2*sigma^2)) 
points(x, y, col="red") 

normal distribution

第二部分

这可能是一种更直接的方法做到这一点,但是这做的伎俩:

p.quint <- qnorm(p = c(0, .2, .4, .6, .8, 1), mean = mu, sd = sigma) 
names(p.quint) <- c(1:5, NA) 

p.quint 
# 1  2  3  4  5  <NA> 
# -Inf 2.739038 3.430699 4.026444 4.718105  Inf  

# Check how many items in p.quint are lower than p and use this as 
# the index to p.quint's names and store it in x.quint 
x.quint <- unlist(lapply(x, function(a) as.numeric(names(p.quint))[sum(a > p.quint)])) 

cbind(x, x.quint) 

#  x x.quint 
# [1,] 1.9  1 
# [2,] 4.8  5 
# [3,] 3.9  3 
# [4,] 4.7  4 
# [5,] 2.3  1 
# [6,] 4.6  4 
# [7,] 3.9  3 

为第二部分,前面的答案

[这是OP mentionned所需的输出将代表昆泰公司前]

好吧,我明白你的意思现在。让我们这样做:

x <- c(1.9,4.8,3.9,4.7,2.3,4.6,3.9) 

# sort x to simplify matters 
x <- sort(x) 

# standardize x around its mean 
x.tr <- x - mean(x) 

# Check range ; we want it to be 4 (5-1) 
range(x.tr)[2] - range(x.tr)[1] # 2.9 

# Apply transformation to stretch the data a little bit 
x.tr <- x * 4/2.9 

range(x.tr)[2] - range(x.tr)[1] 
# [1] 4 

# We also want the min to be 1 
x.tr <- x.tr - (x.tr[1]-1) 

mu <- mean(x.tr) # 3.522167 
sigma <- sd(x.tr) # 1.62172 
x <- x.tr 
curve((1/(sigma*sqrt(2*pi)))*exp(-((x-mu)^2)/(2*sigma^2)),xlim=c(-1,9),ylab="density") 

y.tr <- (1/(sigma*sqrt(2*pi)))*exp(-((x.tr-mu)^2)/(2*sigma^2)) 
points(x.tr, y.tr, col="blue") 

现在你已经把点上的正态分布以下参数范围从1到5:

mu 
# [1] 3.522167 

sigma 
# [1] 1.62172 

second normal distribution

+0

感谢您的回复。 我想根据它们在钟形曲线上的分布(normal dist)来分配1 - 5的评分。你能分享一些相同的知识吗?? – Frankenstein 2015-04-06 06:41:25

+0

哦,我看到你编辑你的问题,让新的评级是五分之一...... – 2015-04-06 06:54:46

+0

是的。它应该在昆泰 – Frankenstein 2015-04-06 07:00:34