2
$\begingroup$

I am using faraway::choccake data, and I want to fit a linear model. I have used the following code:

library(faraway)
attach(chocake)
choccake                 #to have a sense of the data 
choccake.lm<-lm(breakang~recipe+batch+temp,data=choccake)
summary(choccake.lm) 

I have fitted linear model using 'lm' in R before too. But, here the output of summary(choccake.lm) looks a little different.

Here is the output (I'm attaching the choccake data too).

 > choccake
    recipe batch temp breakang
    1        1     1  175       42
    2        1     1  185       46
    3        1     1  195       47
    4        1     1  205       39
    5        1     1  215       53
    6        1     1  225       42
    7        1     2  175       47
    8        1     2  185       29
    9        1     2  195       35
    10       1     2  205       47
    11       1     2  215       57
    12       1     2  225       45
    13       1     3  175       32
    14       1     3  185       32
    15       1     3  195       37
    16       1     3  205       43
    17       1     3  215       45
    18       1     3  225       45
    19       1     4  175       26
    20       1     4  185       32
    21       1     4  195       35
    22       1     4  205       24
    23       1     4  215       39
    24       1     4  225       26
    25       1     5  175       28
    26       1     5  185       30
    27       1     5  195       31
    28       1     5  205       37
    29       1     5  215       41
    30       1     5  225       47
    31       1     6  175       24
    32       1     6  185       22
 33       1     6  195       22
34       1     6  205       29
35       1     6  215       35
36       1     6  225       26
37       1     7  175       26
38       1     7  185       23
39       1     7  195       25
40       1     7  205       27
41       1     7  215       33
42       1     7  225       35
43       1     8  175       24
44       1     8  185       33
45       1     8  195       23
46       1     8  205       32
47       1     8  215       31
48       1     8  225       34
49       1     9  175       24
50       1     9  185       27
51       1     9  195       28
52       1     9  205       33
53       1     9  215       34
54       1     9  225       23
55       1    10  175       24
56       1    10  185       33
57       1    10  195       27
58       1    10  205       31
59       1    10  215       30
60       1    10  225       33
61       1    11  175       33
62       1    11  185       39
63       1    11  195       33
64       1    11  205       28
65       1    11  215       33
66       1    11  225       30
67       1    12  175       28
68       1    12  185       31
69       1    12  195       27
70       1    12  205       39
71       1    12  215       35
72       1    12  225       43
73       1    13  175       29
74       1    13  185       28
75       1    13  195       31
76       1    13  205       29
77       1    13  215       37
78       1    13  225       33
79       1    14  175       24
80       1    14  185       40
81       1    14  195       29
82       1    14  205       40
83       1    14  215       40
84       1    14  225       31
85       1    15  175       26
86       1    15  185       28
87       1    15  195       32
88       1    15  205       25
89       1    15  215       37
90       1    15  225       33
91       2     1  175       39
92       2     1  185       46
93       2     1  195       51
94       2     1  205       49
95       2     1  215       55
96       2     1  225       42
97       2     2  175       35
98       2     2  185       46
99       2     2  195       47
100      2     2  205       39
101      2     2  215       52
102      2     2  225       61
103      2     3  175       34
104      2     3  185       30
105      2     3  195       42
106      2     3  205       35
107      2     3  215       42
108      2     3  225       35
109      2     4  175       25
110      2     4  185       26
111      2     4  195       28
112      2     4  205       46
113      2     4  215       37
114      2     4  225       37
115      2     5  175       31
116      2     5  185       30
117      2     5  195       29
118      2     5  205       35
119      2     5  215       40
120      2     5  225       36
121      2     6  175       24
122      2     6  185       29
123      2     6  195       29
124      2     6  205       29
125      2     6  215       24
126      2     6  225       35
127      2     7  175       22
128      2     7  185       25
129      2     7  195       26
130      2     7  205       26
131      2     7  215       29
132      2     7  225       36
133      2     8  175       26
134      2     8  185       23
135      2     8  195       24
136      2     8  205       31
137      2     8  215       27
138      2     8  225       37
139      2     9  175       27
140      2     9  185       26
141      2     9  195       32
142      2     9  205       28
143      2     9  215       32
144      2     9  225       33
145      2    10  175       21
146      2    10  185       24
147      2    10  195       24
148      2    10  205       27
149      2    10  215       37
150      2    10  225       30
151      2    11  175       20
152      2    11  185       27
153      2    11  195       33
154      2    11  205       31
155      2    11  215       28
156      2    11  225       33
157      2    12  175       23
158      2    12  185       28
159      2    12  195       31
160      2    12  205       34
161      2    12  215       31
162      2    12  225       29
163      2    13  175       32
164      2    13  185       35
165      2    13  195       30
166      2    13  205       27
167      2    13  215       35
168      2    13  225       30
169      2    14  175       23
170      2    14  185       25
171      2    14  195       22
172      2    14  205       19
173      2    14  215       21
174      2    14  225       35
175      2    15  175       21
176      2    15  185       21
177      2    15  195       28
178      2    15  205       26
179      2    15  215       27
180      2    15  225       20
181      3     1  175       46
182      3     1  185       44
183      3     1  195       45
184      3     1  205       46
185      3     1  215       48
186      3     1  225       63
187      3     2  175       43
188      3     2  185       43
189      3     2  195       43
190      3     2  205       46
191      3     2  215       47
192      3     2  225       58
193      3     3  175       33
194      3     3  185       24
195      3     3  195       40
196      3     3  205       37
197      3     3  215       41
198      3     3  225       38
199      3     4  175       38
200      3     4  185       41
201      3     4  195       38
202      3     4  205       30
203      3     4  215       36
204      3     4  225       35
205      3     5  175       21
206      3     5  185       25
207      3     5  195       31
208      3     5  205       35
209      3     5  215       33
210      3     5  225       23
211      3     6  175       24
212      3     6  185       33
213      3     6  195       30
214      3     6  205       30
215      3     6  215       37
216      3     6  225       35
217      3     7  175       20
218      3     7  185       21
219      3     7  195       31
220      3     7  205       24
221      3     7  215       30
222      3     7  225       33
223      3     8  175       24
224      3     8  185       23
225      3     8  195       21
226      3     8  205       24
227      3     8  215       21
228      3     8  225       35
229      3     9  175       24
230      3     9  185       18
231      3     9  195       21
232      3     9  205       26
233      3     9  215       28
234      3     9  225       28
235      3    10  175       26
236      3    10  185       28
237      3    10  195       27
238      3    10  205       27
239      3    10  215       35
240      3    10  225       35
241      3    11  175       28
242      3    11  185       25
243      3    11  195       26
244      3    11  205       25
245      3    11  215       38
246      3    11  225       28
247      3    12  175       24
248      3    12  185       30
249      3    12  195       28
250      3    12  205       35
251      3    12  215       33
252      3    12  225       28
253      3    13  175       28
254      3    13  185       29
255      3    13  195       43
256      3    13  205       28
257      3    13  215       33
258      3    13  225       37
259      3    14  175       19
260      3    14  185       22
261      3    14  195       27
262      3    14  205       25
263      3    14  215       25
264      3    14  225       35
265      3    15  175       21
266      3    15  185       28
267      3    15  195       25
268      3    15  205       25
269      3    15  215       31
270      3    15  225       25

choccake.lm<-lm(breakang~recipe+batch+temp,data=choccake)

> summary(choccake.lm)

Call:
lm(formula = breakang ~ recipe + batch + temp, data = choccake)

Residuals:
 Min       1Q   Median       3Q      Max 
-15.1851  -2.5682  -0.0419   2.7553  13.4816 

Coefficients:
         Estimate Std. Error t value Pr(>|t|)    
      (Intercept)  16.22698    3.63640   4.462 1.22e-05 ***
      recipe2      -1.47778    0.71744  -2.060   0.0404 *  
      recipe3      -1.52222    0.71744  -2.122   0.0348 *  
      batch2       -1.27778    1.60424  -0.796   0.4265    
      batch3       -9.88889    1.60424  -6.164 2.79e-09 ***
       batch4      -13.55556    1.60424  -8.450 2.36e-15 ***
       batch5      -14.44444    1.60424  -9.004  < 2e-16 ***
      batch6      -18.11111    1.60424 -11.289  < 2e-16 ***
      batch7      -19.50000    1.60424 -12.155  < 2e-16 ***
      batch8      -19.44444    1.60424 -12.121  < 2e-16 ***
      batch9      -19.50000    1.60424 -12.155  < 2e-16 ***
      batch10     -18.00000    1.60424 -11.220  < 2e-16 ***
      batch11     -16.94444    1.60424 -10.562  < 2e-16 ***
      batch12     -15.88889    1.60424  -9.904  < 2e-16 ***
      batch13     -14.94444    1.60424  -9.316  < 2e-16 ***
      batch14     -18.94444    1.60424 -11.809  < 2e-16 ***
      batch15     -20.22222    1.60424 -12.605  < 2e-16 ***
      temp          0.15803    0.01715   9.215  < 2e-16 ***
      ---
     Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

     Residual standard error: 4.813 on 252 degrees of freedom
     Multiple R-squared:  0.6783,    Adjusted R-squared:  0.6566 
     F-statistic: 31.25 on 17 and 252 DF,  p-value: < 2.2e-16 

My questions:

  1. the variables are 'recipe', 'batch' and 'temp'..then why for different values of recipe and batch it's showing different coefficient? it seems from the result that there are 17 dependent variables.
  2. why there's no mention of recipe1 and batch1?
  3. is it by any chance computing for several different regression lines?
$\endgroup$

1 Answer 1

0
$\begingroup$
  1. batch and recipe are factors, thus are treated as categorical variables -- linear regression can't work with such directly, hence they are broken down into a series of numerical variables using a certain coding scheme.
  2. due to how the default coding scheme works -- it makes sense because one level is basically a baseline and can be set to zero without any loss of complexity. See this for more details. There are other coding schemes available, though; see ?C.
  3. nope.

BTW you shouldn't use batch variable in your model -- it is just an experiment ID and all correlations with it are accidental and false.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.