由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - 借人气问一个Excel sampling 问题 (转载)
相关主题
Sas问题, 有包子[Help] SAS CODE FOR RANDOM SAMPLING
count unique values in file with 1 million rowsUrgent R Question
问个r问题R function to tabulate a matrix
如何把取值为1的column列出来?[R]how to sample all possible continuous subset from ordered data
请教一个bootstrapping的问题。R data.frame
求助关于Excel IF 的functionone quick question in SAS, thank you!!
R里面用predict()的问题请教...
诚心请教,工作中的一个sampling的问题.sas question
相关话题的讨论汇总
话题: row话题: excel话题: a1话题: j1话题: sampling
进入Statistics版参与讨论
1 (共1页)
l****p
发帖数: 27354
1
【 以下文字转载自 JobHunting 讨论区 】
发信人: lulupp (木有昵称), 信区: JobHunting
标 题: 借人气问一个Excel sampling 问题
发信站: BBS 未名空间站 (Thu Feb 16 15:59:21 2012, 美东)
假定Excel格子里(A1:A9)有9个数:1,2,..., 9.
现在我要随机抽取5个,每次抽一个,抽中的数字不能重复(=sampling without
replacement)。每次抽的时候,要求剩余的数被抽中的几率和数本身的大小成正比。
这样5个数一组,我要很多组(比如5000组)。
谢谢。
g*********r
发帖数: 2847
2
not sure where you are stucked.
write a macro to do:
for i<=5000
1. generate 5 random number
2. decide which numbers get pulled (a little tricky here, since you have to
think one by one)
3. copy&paste
next i
l****p
发帖数: 27354
3
谢谢。我没有高招,不是重复5000次的问题。
笨办法不行,因为我其实有80个数,要选50个,no replacement, 概率不同。我说9个
只是为了说明问题。

to

【在 g*********r 的大作中提到】
: not sure where you are stucked.
: write a macro to do:
: for i<=5000
: 1. generate 5 random number
: 2. decide which numbers get pulled (a little tricky here, since you have to
: think one by one)
: 3. copy&paste
: next i

g*********r
发帖数: 2847
4

只有个位数的集合,笨办法就是最简单的办法,写5个不同的formula就是了。80选50的
话,写50个formula也是可以的。不过效率就不高了。
写个macro:
算概率做随机,
取第一个数,然后flag这个数,剩下的再算概论做随机
循环
没看出哪里不可行

【在 l****p 的大作中提到】
: 谢谢。我没有高招,不是重复5000次的问题。
: 笨办法不行,因为我其实有80个数,要选50个,no replacement, 概率不同。我说9个
: 只是为了说明问题。
:
: to

l****p
发帖数: 27354
5
flag这一步我不会,用小学生的办法会累死人的。不过还是谢谢你的热心~
我现在倒是有了一个主意,就是先with replacement,这样可以生成很多,要多少有多
少,然后再Excel里面去掉重复数(这个命令需要录入Macro,不过这个应该问题不大)。
还没有试。好的话我回来吱一声。

【在 g*********r 的大作中提到】
:
: 只有个位数的集合,笨办法就是最简单的办法,写5个不同的formula就是了。80选50的
: 话,写50个formula也是可以的。不过效率就不高了。
: 写个macro:
: 算概率做随机,
: 取第一个数,然后flag这个数,剩下的再算概论做随机
: 循环
: 没看出哪里不可行

g*********r
发帖数: 2847
6

)。
possibility will change if you do it with replacement
Row 1: numbers
Row 2: flags - set to 1 first
Row 3: CxR1*CxR2/sumproduct(Row 1, Row 2) -s this is the possibility calc
Row 4: CxR4=CxR3 + Cx-1R4 -- create an 0-1 axis
Row 5: if Row 2 = 0, 0 else if rand() between two values next to each other
in Row 4, lable as 0, else 1
copy Row 5 paste over Row 2

【在 l****p 的大作中提到】
: flag这一步我不会,用小学生的办法会累死人的。不过还是谢谢你的热心~
: 我现在倒是有了一个主意,就是先with replacement,这样可以生成很多,要多少有多
: 少,然后再Excel里面去掉重复数(这个命令需要录入Macro,不过这个应该问题不大)。
: 还没有试。好的话我回来吱一声。

D******n
发帖数: 2836
7
How about this?
pertaining to your toy example.
1) fill A1 to I1 with 1 to 9
2) in J1 enter =A1*rand(), and then select J1 and drag trough to R1
3) in S1 enter
=MATCH(LARGE($J1:$R1,COLUMN()-18),$J1:$R1,0)
and then select S1 and drag through to W1
4) select row A1 to W1, and drag it all the way down for as many lines as
you want.

)。

【在 l****p 的大作中提到】
: flag这一步我不会,用小学生的办法会累死人的。不过还是谢谢你的热心~
: 我现在倒是有了一个主意,就是先with replacement,这样可以生成很多,要多少有多
: 少,然后再Excel里面去掉重复数(这个命令需要录入Macro,不过这个应该问题不大)。
: 还没有试。好的话我回来吱一声。

l****p
发帖数: 27354
8
你这个是不是Excel啊?我查了一下,没有查到Excel里面有flag函数。
Possible change也没关系。我举个例子:
3个数:1,2,3
取2个,no replacement. 如果取1和2/3的概率比是1000 000 :1。
那么,如果生成很多很多的2个数的sample.平均下来,1的比例不是近乎100%,而是近
乎50% (50%就是每两个数都含1)。 近乎50%是正确答案。
所以,1的概率如果大,只能让1的比例越接近50%,而不会达到(只要重复次数足够多
)。

other

【在 g*********r 的大作中提到】
:
: )。
: possibility will change if you do it with replacement
: Row 1: numbers
: Row 2: flags - set to 1 first
: Row 3: CxR1*CxR2/sumproduct(Row 1, Row 2) -s this is the possibility calc
: Row 4: CxR4=CxR3 + Cx-1R4 -- create an 0-1 axis
: Row 5: if Row 2 = 0, 0 else if rand() between two values next to each other
: in Row 4, lable as 0, else 1
: copy Row 5 paste over Row 2

l****p
发帖数: 27354
9
这个很有意思。不过,我简化了例子,如果只有1和2,只取1次,要求取到2的可能性是
1的2倍,如果假定从0-2 和0-1之间任取值,前者的值大于后者的可能性是75%, 不是2
/3。
如果延伸到多个数,我试了一下,发觉不对头,弄不下去了。

【在 D******n 的大作中提到】
: How about this?
: pertaining to your toy example.
: 1) fill A1 to I1 with 1 to 9
: 2) in J1 enter =A1*rand(), and then select J1 and drag trough to R1
: 3) in S1 enter
: =MATCH(LARGE($J1:$R1,COLUMN()-18),$J1:$R1,0)
: and then select S1 and drag through to W1
: 4) select row A1 to W1, and drag it all the way down for as many lines as
: you want.
:

g*********r
发帖数: 2847
10

flag is not a function. they are numbers used as indicators and set up to 1
at the beginning.

【在 l****p 的大作中提到】
: 你这个是不是Excel啊?我查了一下,没有查到Excel里面有flag函数。
: Possible change也没关系。我举个例子:
: 3个数:1,2,3
: 取2个,no replacement. 如果取1和2/3的概率比是1000 000 :1。
: 那么,如果生成很多很多的2个数的sample.平均下来,1的比例不是近乎100%,而是近
: 乎50% (50%就是每两个数都含1)。 近乎50%是正确答案。
: 所以,1的概率如果大,只能让1的比例越接近50%,而不会达到(只要重复次数足够多
: )。
:
: other

1 (共1页)
进入Statistics版参与讨论
相关主题
sas question请教一个bootstrapping的问题。
问一个SAS format的问题,看似简单求助关于Excel IF 的function
[R] a row of a matrix is not a matrix?R里面用predict()的问题
如何用R处理大文件诚心请教,工作中的一个sampling的问题.
Sas问题, 有包子[Help] SAS CODE FOR RANDOM SAMPLING
count unique values in file with 1 million rowsUrgent R Question
问个r问题R function to tabulate a matrix
如何把取值为1的column列出来?[R]how to sample all possible continuous subset from ordered data
相关话题的讨论汇总
话题: row话题: excel话题: a1话题: j1话题: sampling