Advertisement
Online Test Banks
Score higher
See Online Test Banks
eLearning
Learning anything is easy
Browse Online Courses
Mobile Apps
Learning on the go
Explore Mobile Apps
Dummies Store
Shop for books and more
Start Shopping

How to Test Data Normality Graphically in R

You could, of course, plot a histogram with R for every data sample you want to look at. You can use the histogram() function pretty easily to plot histograms for different groups.

Using the formula interface, you can plot two histograms at once using the following code:

image0.png
> library(lattice)
> histogram(~temp | factor(activ), data=beaver2)

The histogram() function uses a one-sided formula, so you don’t specify anything at the left side of the tilde (~). On the right side, you specify the following:

  • Which variable the histogram should be created for: In this case, that’s the variable temp, containing the body temperature.

  • After the vertical line (|),the factor by which the data should be split: In this case, that’s the variable activ that has a value 1 if the beaver was active and 0 if it was not. To convert this numeric variable to a factor, you use the factor() function.

The vertical line (|) in the formula interface can be read as “conditional on.” It’s used in that context in the formula interfaces of more advanced statistical functions as well.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win an iPad Mini. Enter to win now!