没有合适的资源?快使用搜索试试~ 我知道了~
首页An_Introduction_to_Categorical_Data_Analysis_Using_R
资源详情
资源评论
资源推荐
An Introduction to Categorical Data Analysis Using R
Brett Presnell
March 28, 2000
Abstract
This document attempts to reproduce the examples and some of the exercises in An Introduction to Categor-
ical Data Analysis [1] using the R statistical programming environment.
Chapter 0
About This Document
This document attempts to reproduce the examples and some of the exercises in An Introduction to Categori-
cal Data Analysis [1] using the R statistical programming environment. Numbering and titles of chapters will
follow that of Agresti’s text, so if a particular example/analysis is of interest, it should not be hard to find,
assuming that it is here.
Since R is particularly versatile, there are often a number of different ways to accomplish a task, and
naturally this document can only demonstrate a limited number of possibilities. The reader is urged to explore
other approaches on their own. In this regard it can be very helpful to read the online documentation for the
various functions of R, as well as other tutorials. The help files for many of the R functions used here are
also included in the appendix for easy reference, but the online help system is definitely the preferred way to
access this information.
It is also worth noting that as of this writing (early 2000), R is still very much under development.
Thus new functionality is likely to become available that might be more convenient to use than some of the
approaches taken here. Of course any user can also write their own R functions to automate any task, so
the possibilities are endless. Do not be intimidated though, for this is really the fun of using R and its best
feature: you can teach it to do whatever is neede, instead of being constrained only to what is “built in.”
A Note on the Datasets
Often in this document I will show how to enter the data into R as a part the example. However, most of the
datasets are avaiable already in R format in the R package for the course, sta4504, available from the course
web site. After installing the library on your computer and starting R, you can list the functions and data files
available in the package by typing
> library(help = sta4504)
> data(package = sta4504)
You can make the files in the package to your R session by typing
> library(sta4504)
and you can read one of the package’s datasets into your R session simply by typing, e.g.,
> data(deathpen)
1
Chapter 1
Introduction
1.3 Inference for a (Single) Proportion
The function prop.test (appendix A.1.3) will carry out test of hypotheses and produce confidence intervals
in problems involving one or several proportions. In the example concerning opinion on abortion, there were
424 “yes” responses out of 950 subjects. Here is one way to use prop.test to analyze these data:
> prop.test(424,950)
1-sample proportions test with continuity correction
data: 424 out of 950, null probability 0.5
X-squared = 10.7379, df = 1, p-value = 0.001050
alternative hypothesis: true p is not equal to 0.5
95 percent confidence interval:
0.4144634 0.4786078
sample estimates:
p
0.4463158
Note that by default:
• the null hypothesis π = .5 is tested against the two-sided alternative π 6= .5;
• a 95% confidence interval for π is calculated; and
• both the test and the CI incorporate a continuity correction.
Any of these defaults can be changed. The call above is equivalent to
prop.test(424,950,p=.5,alternative="two.sided",conf.level=0.95,correct=TRUE)
Thus, for example, to test the null hypothesis that π = .4 versus the one-sided alternative π > .4 and a
99% (one-sided) CI for π, all without continuity correction, just type
prop.test(424,950,p=.4,alternative="greater",conf.level=0.99,correct=FALSE)
2
Chapter 2
Two-Way Contingency Tables
Entering and Manipulating Data
There are a number of ways to enter counts for a two-way table into R. For a simple concrete example,
we consider three different ways of entering the “belief in afterlife” data. Other methods and tools will be
introduced as we go along.
Entering Two-Way Tables as a Matrix
One way is to simply enter the data using the matrix function (this is similar to using the array function
which we will encounter later). For the “belief in afterlife” example, we might type:
> afterlife <- matrix(c(435,147,375,134),nrow=2,byrow=TRUE)
> afterlife
[,1] [,2]
[1,] 435 147
[2,] 375 134
Things are somewhat easier to read if we name the rows and columns:
> dimnames(afterlife) <- list(c("Female","Male"),c("Yes","No"))
> afterlife
Yes No
Female 435 147
Male 375 134
We can dress things even more by providing names for the row and column variables:
> names(dimnames(afterlife)) <- c("Gender","Believer")
> afterlife
Believer
Gender Yes No
Female 435 147
Male 375 134
Calculating the total sample size, n, and the overall proportions, {p
ij
} is easy:
> tot <- sum(afterlife)
> tot
[1] 1091
3
剩余37页未读,继续阅读
sinat_15505677
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- 2023年中国辣条食品行业创新及消费需求洞察报告.pptx
- 2023年半导体行业20强品牌.pptx
- 2023年全球电力行业评论.pptx
- 2023年全球网络安全现状-劳动力资源和网络运营的全球发展新态势.pptx
- 毕业设计-基于单片机的液体密度检测系统设计.doc
- 家用清扫机器人设计.doc
- 基于VB+数据库SQL的教师信息管理系统设计与实现 计算机专业设计范文模板参考资料.pdf
- 官塘驿林场林防火(资源监管)“空天地人”四位一体监测系统方案.doc
- 基于专利语义表征的技术预见方法及其应用.docx
- 浅谈电子商务的现状及发展趋势学习总结.doc
- 基于单片机的智能仓库温湿度控制系统 (2).pdf
- 基于SSM框架知识产权管理系统 (2).pdf
- 9年终工作总结新年计划PPT模板.pptx
- Hytera海能达CH04L01 说明书.pdf
- 数据中心运维操作标准及流程.pdf
- 报告模板 -成本分析与报告培训之三.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0