Skip to content

Instantly share code, notes, and snippets.

@mhughes2k
Created November 1, 2019 15:54
Show Gist options
  • Save mhughes2k/065f7e02c5b29fde475e85f8f264c1fc to your computer and use it in GitHub Desktop.
Save mhughes2k/065f7e02c5b29fde475e85f8f264c1fc to your computer and use it in GitHub Desktop.
<html>
<body>
<form>
<script type="text/javascript" src="http://cdn.datacamp.com/dcl-react.js.gz"></script>
The R session below has a data set called <span class="" style="font-family: &quot;Courier New&quot;, Courier, mono;">bp</span> pre-loaded which contains information on the age (<span class="" style="font-family: &quot;Courier New&quot;, Courier, mono;">Age</span>)
and systolic blood pressure (<span class="" style="font-family: &quot;Courier New&quot;, Courier, mono;">BP</span>) of 30 individuals.&nbsp;
<p>Using the tool below fit a linear regression model called <span class="" style="font-family: &quot;Courier New&quot;, Courier, mono;">BP_mod</span>, which takes <span class="" style="font-family: &quot;Courier New&quot;, Courier, mono;">BP</span> as the
response using <span class="" style="font-family: &quot;Courier New&quot;, Courier, mono;">Age</span> as the independent variable, then print the model results.<br>
<script type="text/javascript" src="//cdn.datacamp.com/dcl-react.js.gz"></script>
</p>
<div data-datacamp-exercise="" data-lang="r" style="width: 900px" data-height="400px" data-show-run-button="" data-no-lazy-load="" align="center">
<code data-type="pre-exercise-code">
# Pre-exercise code initialises the workspace for the example
bp &lt;- read.csv("http://personal.strath.ac.uk/kate.pyper/Class_Data/Blood_Pressure.csv")
</code>
<code data-type="sample-code">
# construct BP_mod
# Print the results of BP_mod
</code>
<code data-type="solution">
# construct BP_mod
BP_mod &lt;- lm(BP~Age, data=bp)
# Print the results of BP_mod
summary(BP_mod)
</code>
<code data-type="sct">
ex() %&gt;% { check_error(.)
check_function(.,"lm") %&gt;% check_arg(., "data","Remember to use the 'data' argument to direct the function to your data")
check_object(., "BP_mod", undefined_msg="Did you call your model BP_mod? Remember that object names in R are case sensitive!") %&gt;% check_equal(., incorrect_msg="Check the formula specified in the lm() function")
check_function(., "summary") }
success_msg("Excellent! You can now draw conclusions based on this model. Enter the code 219279 in the box below to continue.")
</code>
<div data-type="hint">
Use the <code>data=</code> argument to <code> lm </code> and remember that <code>summary()</code> prints the results from a linear model.
</div>
</div>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment