Hand Coding a Linear Model function

In yesterday’s post we developed a method for constructing a multivariate linear model with an intercept. Today we will turn the collection of loose commands into an integrated and easy to use function. A small recap from yesterday. We start by loading data and assigning our variables to objects {% highlight r %} data(iris) x1 <- iris$Petal.Width x2 <- iris$Sepal.Length y <- iris$Petal.Length {% endhighlight %} We now construction our linear model, the fastest way of doing this is using the QR decomposition.

Hand Coding Categorical Variables

In last week’s posts we discussed handcoding a linear model and writing a convenient function for this, in today’s post we will take this a step further by including a categorical variable. Swiss life Since I live in Geneva we will use a built-in data set that is close to home. {% highlight r %} data(“swiss”) {% endhighlight %} This data set compares fertility rates in 47 different French-speaking regions (sub-Cantonal) of Switzerland around the year 1888 (for more information see help("swiss")).

© Some rights reserved.

Using the Chirpy theme for Hugo.