Cs446 Tool Using Formulas Within Functions
Cs446 Tool Using Formulas Within Functions
The examples below are based on the titanic data set you examined in this course. You can use
the titanic data set to ask many different questions that have varying levels of complexity.
Writing a Formula
When you answer a bivariate question about the association between two variables, you’ll need to
visualize or summarize a variable for different values of one or more other variables. For example,
if you want to understand the association between a passenger’s sex and their survival, SurvBin
will be grouped by Sex. In this scenario, your formula is:
SurvBin ~ Sex.
When you answer a multivariate question, you are assessing one variable in terms of multiple other
variables. For example, if you want to understand how a passenger’s class influences the association
of SurvBin and Sex, all you need to do is change the formula to add the variable PClass:
SurvBin ~ Sex + PClass.
function (Variable1 ~ Variable2 + The formula you want to use. The variables
Variable3, need to match the names of the variables
in your data set.
data = dataset)
The command below on the left creates a table, prop1, that calculates the mean survival of Titanic
passengers by their sex. The command below on the right creates a table, prop2, that calculates
the mean survival of Titanic passengers by both sex and passenger class.