频率分布问题 [英] Frequency Distribution question

查看:84
本文介绍了频率分布问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我认为我的问题相当简单,但我似乎无法在我尝试完成时将
复制旧的SAS频率程序这个在

MS Access。


无论如何,我对调查中有大约10个问题有可能的回复

范围来自0-4。


我想做的只是表明,对于每个问题我们都有x

每个类别的回复数量,相当于所有

回复的百分比:


如果我们对问题1的5次调查得到以下回复

1

2

2

3




频率分配会看起来像:

1 1 20%

2 2 40%

3 1 20%

4 1 20 %


我可以通过使用查询

并选择两次字段,然后使用groupby来获得一个问题(或至少是频率)第一栏和

计入第二列。但是,如果我尝试在接下来的两列中为下一个字段执行此操作,那么它会解决所有问题。


有人可以帮助我吗?

谢谢,

Tim Brooks

Hello,
I think the question i have is fairly straightforward, but I can''t seem to
replicate the old SAS frequency procedure when I try to accomplish this in
MS Access.

anyway, i have about 10 questions on a survey that have a possible response
range from 0-4.

what I would like to do is simply show that for each question we had x
amount of responses in each category, which amount to x percentage of all
responses:

so if we have the following responses to 5 surveys for question 1
1
2
2
3
4

the frequency distribution would look like:
1 1 20%
2 2 40%
3 1 20%
4 1 20%

I can get this (or at least the frequency) for one question by using a query
and selecting the field twice, then using groupby in the first column and
count in the second column. But if I try to do this for the next field in
the next 2 columns it screws everything up.

can someone help me?
thanks,
Tim Brooks

推荐答案

你好蒂姆,


我接受了这个挑战......我喜欢偶尔这样做,作为一个学习的机会。 :)


这就是我想出来的,虽然我确定有人会有更好的想法。

存储计算值通常不是一个好主意,所以我认为完成此任务的

正确方法可能是使用交叉表查询

(我很沮丧。)


我的计划需要3张桌子。

tblQuestions可以保存你的10个问题。

tblResponses持有对这些问题的100个回复。 (一个到

多次加入)

tblResults存储响应的计数,以及百分比计算


我输了10个问题进入tblQuestions,但是懒得输入100

随机响应,所以我编写了一些代码来为我做这个。

我得到了响应数据之后,我写了更多代码将

计算数据写入tblResults。


我的代码从未绑定表单上的两个命令按钮运行,结果

显示在名为sbfResults的数据表样式子表单中,基于tblResults,这是



希望以上内容对您有所帮助了解此代码的工作原理:

*********************************** *************** **********

期权比较数据库

期权明确


Private Sub cmdRandomResponse_Click()

''我们有10个问题,每个问题需要100个随机回复


昏暗的MyDB作为DAO.Database

设置MyDB = CurrentDb


Dim rstQ作为DAO.Recordset

Dim rstR作为DAO.Recordset


设置rstQ = MyDB.OpenRecordset(" tblQuestions",dbOpenTable)

设置rstR = MyDB.OpenRecordset(" tblResponses",dbOpenDynaset)


Dim i As Integer

Dim MyQ As Long

Dim MyR As Long


随着rstQ

。移动最后

。移动第一次

直到.EOF''这里有10个问题

MyQ =!QNbr''两个表都有一个QNbr字段(长整数--- 1到

很多)

用rstR

对于i = 0到99''这里是100随机响应的地方

创建

.AddNew

!QNbr = MyQ

''Int((上限 - 下限+ 1)* Rnd +下限)

!响应= Int((4 - 0 + 1)* Rnd + 0)

。更新

下一页我

结束

.MoveNext

Loop


。关闭

结束


rstR.Close


套装rstR = Nothing

Set rstQ = Nothing

设置MyDB = Nothing

End Sub

***** ********************************************* ***** *****

Private Sub cmdTabulateResults_Click()


''现在我们有10个问题,每个问题有100个回复,并希望

将结果制成表格

Dim MyDB作为DAO.Database

设置MyDB = CurrentDb


Dim rstQ作为DAO .Recordset

Dim rstResults作为DAO.Recordset


设置rstQ = MyDB.OpenRecordset(" tblQuestions",dbOpenTable)

设置rstResults = MyDB.OpenRecordset(" tblResults",dbOpenDynaset)


Dim i As Integer

Dim MyQ As Long

Dim MyR As Long


Dim MyCountQ As Long

Dim MyCountR As Long

Dim MyPcnt


Dim MyMin

Dim MyMax

''清除结果表。下面的代码用当前的

结果重新填充它。

MyDB.Execute" DELETE tblResults。* FROM tblResults;",dbFailOnError

>
随着rstQ

。移动最后

。移动首先

Do Until .EOF''这是问题...循环通过他们一次一个。

MyQ =!QNbr

rstResults

''每个问题应该有4个可能的答案,但是谁

肯定知道吗?这检查。

MyMin = DMin(响应,tblResponses,([QNbr] =& MyQ&

) ")

MyMax = DMax(" Response"," tblResponses","([QNbr] =& MyQ&

") ")


i = MyMin To MyMax

.AddNew

!QuestionNumber = MyQ

!响应= i

MyCountQ = DCount(" QNbr"," tblResponses","([QNbr] =& MyQ

&" ;)")

MyCountR = DCount(响应,tblResponses,([QNbr] ="&

MyQ&" ;)和([Response] ="& i&")")


MyPcnt =(MyCountR / MyCountQ)

!ResponsePercent = MyPcnt

!ResponseCount = MyCountR

。更新

下一页我

结束

.MoveNext

循环


。关闭

结束

Set rstResults = Nothing

Set rstQ = Nothing

设置MyDB = Nothing


Me.Refresh''我有一个基于tblResults的子表单,这样我就可以立即显示结果

结束子

***** ********************************************* ***** *****

-

HTH,

Don

======== =====================

使用我的*****@Telus.Net 电子邮件

免责声明:

Professional PartsPerson

业余数据库程序员{: o)


我是Access97用户,因此所有发布的代码

样本也基于Access97

除非另有说明注意。


Do SinksIn = True

文件/保存,<书桌抽屉里的手指>

循环


================================

NC Tim < TB ************** @ mindspring.com>在消息中写道

news:u2 ****************** @ newsread2.news.atl.earth link.net ...
Hi Tim,

I took this on as a challenge ... I like to do that occasionally as an
opportunity to learn. :)

Here''s what I came up with, although I''m sure that someone will have a
better idea.
It''s generally not a good idea to store calculated values, so I think the
correct method to accomplish this task might be to use a crosstab query
(which I suck at.)

My plan calls for 3 tables.
tblQuestions holds your 10 questions.
tblResponses holds the 100 responses to each of those questions. (one to
many join)
tblResults stores the counts the responses, and the percentage calculations

I did enter 10 questions into tblQuestions, but was too lazy to enter 100
random responses, so I made up some code to do that for me.
After I had the response data, I wrote some more code to write the
calculated data to tblResults.

My code runs from two command buttons on an unbound form, and the results
are displayed in a datasheet-style subform called "sbfResults", which is
based on tblResults.

Hopefully the above will help you to understand how this code works:
************************************************** **********
Option Compare Database
Option Explicit

Private Sub cmdRandomResponse_Click()
''We have 10 questions, and want 100 random responses to each question

Dim MyDB As DAO.Database
Set MyDB = CurrentDb

Dim rstQ As DAO.Recordset
Dim rstR As DAO.Recordset

Set rstQ = MyDB.OpenRecordset("tblQuestions", dbOpenTable)
Set rstR = MyDB.OpenRecordset("tblResponses", dbOpenDynaset)

Dim i As Integer
Dim MyQ As Long
Dim MyR As Long

With rstQ
.MoveLast
.MoveFirst
Do Until .EOF ''Here are the 10 Questions
MyQ = !QNbr ''Both tables have a QNbr field (long integer --- 1 to
many)
With rstR
For i = 0 To 99 ''Here is where the 100 random responses are
created
.AddNew
!QNbr = MyQ
''Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
!Response = Int((4 - 0 + 1) * Rnd + 0)
.Update
Next i
End With
.MoveNext
Loop

.Close
End With

rstR.Close

Set rstR = Nothing
Set rstQ = Nothing
Set MyDB = Nothing
End Sub
************************************************** **********
Private Sub cmdTabulateResults_Click()

''Now we have 10 questions, 100 responses to each question, and want to
tabulate the results
Dim MyDB As DAO.Database
Set MyDB = CurrentDb

Dim rstQ As DAO.Recordset
Dim rstResults As DAO.Recordset

Set rstQ = MyDB.OpenRecordset("tblQuestions", dbOpenTable)
Set rstResults = MyDB.OpenRecordset("tblResults", dbOpenDynaset)

Dim i As Integer
Dim MyQ As Long
Dim MyR As Long

Dim MyCountQ As Long
Dim MyCountR As Long
Dim MyPcnt

Dim MyMin
Dim MyMax

''Clear out the results table. The code below re-populates it with current
results.
MyDB.Execute "DELETE tblResults.* FROM tblResults;", dbFailOnError

With rstQ
.MoveLast
.MoveFirst
Do Until .EOF ''Here are the Questions ... Loop thru them one at a time.
MyQ = !QNbr
With rstResults
''There should be 4 possible responses to each question, but who
knows for sure? This checks.
MyMin = DMin("Response", "tblResponses", "([QNbr] = " & MyQ &
")")
MyMax = DMax("Response", "tblResponses", "([QNbr] = " & MyQ &
")")

For i = MyMin To MyMax
.AddNew
!QuestionNumber = MyQ
!Response = i
MyCountQ = DCount("QNbr", "tblResponses", "([QNbr] = " & MyQ
& ")")
MyCountR = DCount("Response", "tblResponses", "([QNbr] = " &
MyQ & ") And ([Response] = " & i & ")")

MyPcnt = (MyCountR / MyCountQ)
!ResponsePercent = MyPcnt
!ResponseCount = MyCountR
.Update
Next i
End With
.MoveNext
Loop

.Close
End With
Set rstResults = Nothing
Set rstQ = Nothing
Set MyDB = Nothing

Me.Refresh ''I have a subform based on tblResults, so that I can immediately
display the results

End Sub
************************************************** **********
--
HTH,
Don
=============================
Use My*****@Telus.Net for e-mail
Disclaimer:
Professional PartsPerson
Amateur Database Programmer {:o)

I''m an Access97 user, so all posted code
samples are also Access97- based
unless otherwise noted.

Do Until SinksIn = True
File/Save, <slam fingers in desk drawer>
Loop

================================
"NC Tim" <tb**************@mindspring.com> wrote in message
news:u2******************@newsread2.news.atl.earth link.net...
你好,
我认为我的问题相当简单,但当我试图在
MS中完成此操作时,我似乎无法复制旧的SAS频率程序访问。

无论如何,我在调查中有大约10个问题,可能会有0到4美元的b $ b响应范围。

我想做的是只是表明,对于每个问题,我们在每个类别中都有x
响应量,这相当于所有回复的x百分比:

所以,如果我们有以下回答5调查问题1
1
2
3
4频率分布如下:
1 1 20%
2 2 40%
3 1 20%
4 1 20%

我可以通过使用一个问题得到这个(或至少是频率) a
查询并选择该字段两次,然后在第一个c中使用groupby olumn和
计入第二列。但是如果我试着在下两个栏目的下一个栏目中做这个,那就搞砸了一切。

有人可以帮助我吗?
谢谢,
蒂姆布鲁克斯
Hello,
I think the question i have is fairly straightforward, but I can''t seem to
replicate the old SAS frequency procedure when I try to accomplish this in
MS Access.

anyway, i have about 10 questions on a survey that have a possible response range from 0-4.

what I would like to do is simply show that for each question we had x
amount of responses in each category, which amount to x percentage of all
responses:

so if we have the following responses to 5 surveys for question 1
1
2
2
3
4

the frequency distribution would look like:
1 1 20%
2 2 40%
3 1 20%
4 1 20%

I can get this (or at least the frequency) for one question by using a query and selecting the field twice, then using groupby in the first column and
count in the second column. But if I try to do this for the next field in
the next 2 columns it screws everything up.

can someone help me?
thanks,
Tim Brooks



唐,


我的妻子正在考虑在工作中进行一项小型调查,正在寻找对于选项;

如果可能的话,我当然会感谢你的数据库的一个例子,

传给她。


干杯,


Dave(db*****@ns.sympatico.ca)

(请输入文件,或更改扩展名,即mydatabase.txt)


" Don Leverton" <乐**************** @ telusplanet.net>在消息中写道

news:36Agc.49382
Don,

My wife is considering a small survey at work, and is looking for options;
if possible, I would certainly appreciate an example of your database to
pass along to her.

Cheers,

Dave (db*****@ns.sympatico.ca)
(Please Zip file, or change extension, i.e. mydatabase.txt)

"Don Leverton" <le****************@telusplanet.net> wrote in message
news:36Agc.49382


aD.12596@edtnps89 ...
aD.12596@edtnps89...
嗨Tim,

我接受了这个挑战......我喜欢偶尔这样做,以此作为学习的机会。 :)

这就是我的想法,.......>
Hi Tim,

I took this on as a challenge ... I like to do that occasionally as an
opportunity to learn. :)

Here''s what I came up with, .......>



这篇关于频率分布问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆