library(mosaic) library(statisticalModeling) library(MultipleChoice) tutorial::go_interactive()
Given data and a model design, the computer will find the model function and model values for you.  As an example, consider the Current Population Survey  data mosaicData::CPS85.  Suppose you want to build a model with wage as a response variable and age and sex as explanatory variables incorporated as main terms.  Also include the intercept term, as usual.
The two arguments to lm() are:
wage ~ 1 + age + sex.data = CPS85data(CPS85, package = "mosaicData") mod1 <- lm( wage ~ 1 + age + sex, data = CPS85)
The mod1 <-... part of the command simply gives the model a
name so that you can use it later on.  If you construct more than one
model, it makes sense to give them different names. 
In making a graph of the function, the model values will always be plotted on the vertical axis.  But you have a choice of what to put on the horizontal axis.  This plot puts the quantitative variable age on the x-axis, and uses color for sex.
fmodel(mod1, ~ age + sex)
You could arrange things the other way as well.
fmodel(mod1, ~ sex + age)
Note that the line in this plot is merely to guide the eye. The sex variable is categorical and so it's meaningless to interpolate between values.
Your task ... re-create each of the above graphs using the fmodel() command. The two arguments to fmodel() are
mod1.~ age + sex or ~ sex + age.b <- 5
# Create a variable a, equal to 5 # Print out a
# Create a variable a, equal to 5 a <- 5 # Print out a a
test_object("a") test_output_contains("a", incorrect_msg = "Make sure to print `a`.") success_msg("Great!")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.