• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
The Analysis Factor

The Analysis Factor

Statistical Consulting, Resources, and Statistics Workshops for Researchers

  • Home
  • Our Programs
    • Membership
    • Online Workshops
    • Free Webinars
    • Consulting Services
  • About
    • Our Team
    • Our Core Values
    • Our Privacy Policy
    • Employment
    • Collaborate with Us
  • Statistical Resources
  • Contact
  • Blog
  • Login

Random Sample from a Uniform Distribution in R Commander

by Karen Grace-Martin Leave a Comment

Why We Needed a Random Sample of 6 numbers between 1 and 10000

As you may have read in one of our recent newsletters, this month The Analysis Factor hit two milestones:

  1. 10,000 subscribers to our mailing list
  2. 6 years in business.

We’re quite happy about both, and seriously grateful to all members of our community.

So to celebrate and to say thanks, we decided to do a giveaway to 6 randomly-chosen  newsletter subscribers.

I just sent emails to the 6 winners this morning.

How We Randomly Generated 6 Equally Likely Values out of 10000 Using R Commander

And since randomly generating numbers is something you often need to do in research, I thought I would let you know how we did it.

I decided to use R Commander as it’s extremely easy to use, and I wanted to check it out for our upcoming workshop.

Here’s how I did it.

I exported the names and email addresses of everyone on our mailing list into excel and sorted by the date and time in which they subscribed.

We actually had 10010 email addresses on the list, but I removed those of our employees, which brought us down to exactly 10,000.

In R commander, I simple asked for it to create a random sample from a uniform distribution.

As you can see from the menus, it’s possible to get a random sample from many different distributions, but I wanted Uniform, which has an equal probability of every value within a specific range.

uniform_menu

This brings up this dialog box.  Because the first row of my excel spreadsheet contained the Variable names (name, email address, etc.) I didn’t want to randomly choose row 1.  So I started it at 2 and went through 10001.

I technically only needed 6 observations, not 25, but wanted to select a few extra people, just in case someone is using an old email address and doesn’t respond to our offer.

Sure, 25 was probably overkill, but hey, I like to have backups.

dialog_uniform

And this is what the data looks like:

Data Set

As you can see, one of the very nice things about R Commander is being able to see and edit the data set.

The other nice thing is that, much like the Paste function in SPSS, R commander doesn’t just run whatever you choose in the menus, it also pastes the code for those menu options into a script window.

At the top is the code for what I just did in the menus.  The nice thing is that this script is editable.  Say I realized that 25 really was too many.  I can simply change that 25 to something like 12 (it’s not hard to find in the script), then hit Submit and it will rerun it.

This is a great way to learn R code without having to struggle with lots of errors.

RCommander_window

The output, as you can see, is at the bottom.  I simply copied and pasted these into an excel file, rounded off to the nearest integer, and matched up the random numbers from my sample with the row numbers in excel.

RforSPSSusers_icon_smallThere are some very nice tools for R that have the nice intuitive, menu-based interface that SPSS does. You can learn about them in this 2.5 hour webinar starting Tues, August 19 @ 2pm EDT (UTC-4).
Getting Started with R
Kim discusses the use of R statistical software for data manipulation, calculation, and graphical display.

Tagged With: R Commander, random sample, Uniform distribution

Related Posts

  • Ways to Customize a Scatter Plot in R Commander
  • Member Training: R for Menu Users Software Tutorial
  • Member Training: What’s the Best Statistical Package for You?
  • The Advantages of RStudio

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Please note that, due to the large number of comments submitted, any questions on problems related to a personal study/project will not be answered. We suggest joining Statistically Speaking, where you have access to a private forum and more resources 24/7.

Primary Sidebar

This Month’s Statistically Speaking Live Training

  • Member Training: Analyzing Pre-Post Data

Upcoming Free Webinars

Poisson and Negative Binomial Regression Models for Count Data

Upcoming Workshops

  • Analyzing Count Data: Poisson, Negative Binomial, and Other Essential Models (Jul 2022)
  • Introduction to Generalized Linear Mixed Models (Jul 2022)

Copyright © 2008–2022 The Analysis Factor, LLC. All rights reserved.
877-272-8096   Contact Us

The Analysis Factor uses cookies to ensure that we give you the best experience of our website. If you continue we assume that you consent to receive cookies on all websites from The Analysis Factor.
Continue Privacy Policy
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT