Page 190 - Data Science Algorithms in a Week
P. 190

R Reference


            Linear regression

            R is equipped with the command lm to fit the linear models:

            Input:

                source_code/appendix_b_r/example07_linear_regression.r
                temperatures = data.frame(
                    fahrenheit = c(5,14,23,32,41,50),
                    celsius = c(-15,-10,-5,0,5,10)
                )
                model = lm(celsius ~ fahrenheit, data = temperatures)
                print(model)
            Output:

                $ Rscript example07_linear_regression.r
                Call:
                lm(formula = celsius ~ fahrenheit, data = temperatures)
                Coefficients:
                (Intercept)   fahrenheit
                   -17.7778       0.5556




































                                                    [ 178 ]
   185   186   187   188   189   190   191   192   193   194   195