David Lillis

R Is Not So Hard! A Tutorial, Part 17: Testing for Existence of Particular Values

August 25th, 2014 by

Sometimes you need to know if your data set contains elements that meet some criterion or a particular set of criteria.

For example, a common data cleaning task is to check if you have missing data (NAs) lurking somewhere in a large data set.

Or you may need to check if you have zeroes or negative numbers, or numbers outside a given range.

In such cases, the any() and all() commands are very helpful. You can use them to interrogate R about the values in your data. (more…)


R Is Not So Hard! A Tutorial, Part 16: Counting Values within Cases

August 19th, 2014 by


SPSS has the Count Values within Cases option, but R does not have an equivalent function. Here are two functions that you might find helpful, each of which counts values within cases inside a rectangular array. (more…)


R Is Not So Hard! A Tutorial, Part 15: Counting Elements in a Data Set

August 13th, 2014 by

Combining the length() and which() commands gives a handy method of counting elements that meet particular criteria.

b <- c(7, 2, 4, 3, -1, -2, 3, 3, 6, 8, 12, 7, 3)
b

Let’s count the 3s in the vector b. (more…)


Generalized Linear Models in R, Part 3: Plotting Predicted Probabilities

July 2nd, 2014 by

In our last article, we learned about model fit in Generalized Linear Models on binary data using the glm() command. We continue with the same glm on the mtcars data set (regressing the vs variable on the weight and engine displacement).

Now we want to plot our model, along with the observed data.

Although we ran a model with multiple predictors, it can help interpretation to plot the predicted probability that vs=1 against each predictor separately.  So first we fit a glm for only (more…)


Generalized Linear Models in R, Part 2: Understanding Model Fit in Logistic Regression Output

June 24th, 2014 by

In the last article, we saw how to create a simple Generalized Linear Model on binary data using the glm() command. We continue with the same glm on the mtcars data set (more…)


Generalized Linear Models in R, Part 1: Calculating Predicted Probability in Binary Logistic Regression

June 18th, 2014 by

Ordinary Least Squares regression provides linear models of continuous variables. However, much data of interest to statisticians and researchers are not continuous and so other methods must be used to create useful predictive models.

The glm() command is designed to perform generalized linear models (regressions) on binary outcome data, count data, probability data, proportion data and many other data types.

In this blog post, we explore the use of R’s glm() command on one such data type. Let’s take a look at a simple example where we model binary data.

(more…)