R Language Learning notes: simple regression analysis

Source: Internet
Author: User

Fitbit <-read.csv ("Fitbit.csv")

Date cal Step Dist floor sit inactive walk run
1 January 1, 2014 2496 12803 9.14 15 1161 123 98 58
2 January 2, 2014 2513 12955 9.47 12 1188 112 67 73
3 January 3, 2014 2228 8768 6.31 16 1234 97 72 37
4 January 4, 2014 2336 8971 6.41 16 1140 174 113 13
5 January 5, 2014 2508 12078 9.05 8 1153 130 108 49
6 January 6, 2014 2763 15880 11.36 20 1061 177 141 61
7 January 7, 2014 2453 10895 7.78 12 1145 156 99 40
8 January 8, 2014 2449 11692 8.44 13 1164 121 118 37

Attach (Fitbit) #可以直接用step表示fitbit $step.

Plot (step, Dist)

Looking at the correlation between step and dist, you can see that the value is almost equal to 1, indicating that the step number is strongly correlated with the distance.

Cor (step, Dist)
[1] 0.9998078

For a simple linear regression:

Dist.step <-LM (dist ~ step, Fitbit)

Display the value of Dist.step to see:

Call : lm (formula = Dist ~ step, data = Fitbit)

Coefficients:
(Intercept) Step
-0.0059966 0.0007171

Description Fit formula: Dist = -0.0059966 + 0.0007171 * Step

You can use the Abline function to draw a fitting line:

Abline (Dist.step)

There is also a more cow car bag, you can draw a more powerful graphics at once:

Library (CAR)

Scatterplot (dist ~ step, data = Fitbit)

Next to the coordinate system there is a box-line diagram, which automatically draws the fitted line.

You can look at the relationship between calorie consumption and step count:

Scatterplot (cal ~ step, data = Fitbit, Spread=false)

You can see that this function automatically fits a straight line and a curve.

R Language Learning notes: simple regression analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.