Publications by Ken Kleinman
Example 7.2: Simulate data from a logistic regression
It might be useful to be able to simulate data from a logistic regression (section 4.1.1). Our process is to generate the linear predictor, then apply the inverse link, and finally draw from a distribution with this parameter. This approach is useful in that it can easily be applied to other generalized linear models. In this examp...
1516 sym R (410 sym/2 pcs) 2 img
Book now discounted 33% at Amazon!
Our book, SAS and R: Data Management, Statistical Analysis, and Graphics, is discounted by a full third at Amazon. With free shipping! Also, they claim if it is further discounted before it ships, they’ll give you the reduced price. Related To leave a comment for the author, please follow the link and comment on their blog: SAS...
638 sym 2 img
Example 7.3: Simple jittered scatterplot with smoother for dichotomous outcomes with continuous predictors
It’s useful to look at scatterplots even when the “y” variable is dichotomous. For example, this can help determine whether categorization or linear assumptions would be more plausible. However, an unmodified scatterplot is less than helpful, since all of the “y” values are either 0 or 1, and are hard to separate visually....
1728 sym R (252 sym/2 pcs) 4 img
Example 7.4: A prettier jittered scatterplot
The plot in section 7.3 has some problems. At the very least, the jittered values ought to be between 0 and 1, so the smoothed lines fit better with them. Once again we use the data generated in section 7.2 as an example. For both SAS and R, we use conditioning (section 1.11.2) to make the jitter happen within the 0-1 range.SASIn SA...
1363 sym R (669 sym/2 pcs) 6 img
Example 7.5: Replicating a prettier jittered scatterplot
The scatterplot in section 7.4 is a plot we could use repeatedly. We demonstrate how to create a macro (SAS, section A.8) and a function (R, section B.5) to do it more easily.SAS%macro logiplot(x=x, y=y, data=, jitterwidth=.05, smooth=50); data lp1; set &data; if &y eq 0 or &y eq 1; jitter = uniform(0) * &jitterwidth; if &y eq 1 then...
854 sym R (1251 sym/4 pcs) 6 img
Example 7.6: Find Amazon sales rank for a book
In honor of Amazon’s official release date for the book, we offer this blog entry.Both SAS and R can be used to find the Amazon Sales Rank for a book by downloading the desired web page and ferreting out the appropriate line. This code is likely to break if Amazon’s page format is changed (but it worked as of July, 2009). In thi...
1615 sym R (1325 sym/4 pcs) 4 img
Example 7.7: Tabulate binomial probabilities
Suppose we wanted to assess the probability P(X=x) for a binomial random variate with n = 10 and with p = .81, .84, …, .99. This could be helpful, for example, in various game settings. In SAS, we find the probability that X=x using differences in the CDF calculated via the cdf function (1.10.1). We loop through the various binomi...
1876 sym R (1753 sym/5 pcs) 4 img
Book now shipping from Amazon
Amazon now reports that the book is in stock! The current discount is 13%.Or, order from the publisher. If you are an ASA member, you can use the online discount code 634LH to obtain a 15% discount. Related To leave a comment for the author, please follow the link and comment on their blog: SAS and R. R-bloggers.com offers daily ...
603 sym 4 img
Example 7.8: Plot two empirical cumulative density functions using available tools
The empirical cumulative density function (CDF) (section 5.1.16) is a useful way to compare distributions between populations. The Kolmogorov-Smirnov (section 2.4.2) statistic D is the value of x with the maximum distance between the two curves. As an example, we compare the male and female distributions of pcs from the HELP data set...
1834 sym R (510 sym/3 pcs) 6 img
Example 7.9: Get data from SAS into R
Some people use both SAS and R in their daily work. They might be more familiar with SAS as a tool for manipulating data and R preferable for plotting purposes. While our goal in the book is to enable people to avoid having to switch back and forth, the following example shows how to move data from SAS into R. Our use of Stata forma...
2236 sym R (873 sym/2 pcs) 6 img