Announcements
This web site is old. The current version of the course is at https://www.stat.umn.edu/geyer/f22/5421/.
The slides for the talk about reproducibility.
Announcements from Previous Years
Arguments of R functions factor
and ordered
The example in the notes
for ordered categorical data serves as a poor example of R function
ordered
that creates an ordered factor. The example is
completely correct, but isn't doing the same thing as in homework problem 4-3.
-
In the example, the data (from Agresti) has numerical values (1, 2, 3)
which the code in the example takes to be the levels of the ordered category.
But since we don't like those as category names, we supply the correct
names at the
labels
argument to R functionordered
. -
In the homework, the data (from me) has character values
(
"not injured"
,"injured, no ER"
,"injured, ER, not hospitalized"
,"hospitalized did not die"
,"died"
). So there isn't a pre-existing order. If you don't specify an order of categories, R will take alphabetical order, which is not what is wanted. Thus you have to supply the correct order as thelevels
argument to R functionordered
. -
You could also use the argument
labels
to specify different category names (perhaps abbreviated). -
In short, arguments
levels
andlabels
work very differently, and you have to know which you want.-
Argument
levels
is for specifying the order of the factor levels. -
Argument
labels
is for changing the names of the factor levels.
-
Argument
- Everything above also applies to R function
factor
which makes unordered or ordered factors.
Search this Website
This web site has no index, so in order to find stuff one needs to use a search engine. Here is how to do that. For example, if you want to find information on Poisson sampling, then the search
"Poisson sampling" site:www.stat.umn.edu/geyer/5421does that. This works either with Google or with DuckDuckGo. The quotation marks mean find the exact phrase. If they are left off, then the search engine will return results that have the word Poisson and the word distribution, not necessarily in the same section much less in the same sentence. The magic is the
site:
part, which
tells the search engine only to look in that site. The site can be made more restrictive, for example,
"Poisson sampling" site:www.stat.umn.edu/geyer/5421/notessays to look only in the notes directory.
Plain R
This course will use plain R rather than Rstudio.
You can use Rstudio if you want, but I don't need anything it does.
R Packages
There are two R packages designed specifically for this course
and numerous other packages used in course notes and examples. R packages that are used in the homework solutions include Install these packages in R by executing the commandspkgs <- c("CatDataAnalysis", "glmbb", "mcmc", "network", "ump") install.packages(pkgs)at the R command line or, of you prefer, by mousing around in menus of the R app or Rstudio. (Packages KernSmooth and MASS do not need to be installed because they are R recommended packages installed by default when R is installed.)
R markdown
My introduction to R markdown is on my Stat 3701 web pages: An Rmarkdown Demo. Both the R markdown source (Rmd file) and the output (either HTML or PDF file) are linked there.
Other material about R markdown can be found at rstudio.com and in the books
- R Markdown: The Definitive Guide"
- the R Markdown Cookbook
- bookdown: Authoring Books and Technical Documents with R Markdown
Hopefully, you will not need any of these books to do the homework. Since all of the course notes and homework assignments are in R markdown, you can always look at the source and see how I did anything you see in the notes or homework assignments.
Downloading Files
One student and perhaps others have had trouble getting the file for homework problem 4-3. Apparently some computer vendors believe in handcuffing users so severely they cannot get any work done. So here is an alternative procedure.
- Use a web browser to download the file table-8.18.txt to your computer. Put it in the same directory (also called folder) as your Rmarkdown file.
- Then use the command
read.table("table-8.18.txt", header = TRUE)
to read the file.