@@ -178,7 +178,7 @@ set.seed(7)
178
178
mydatC <- data.frame (x = sort(rnorm(49 )), ch = c(LETTERS [1 : 3 ], letters [1 : 4 ]))
179
179
mydatC $ y <- with(mydatC , 20 * x + 10 - (ch2num(ch ) - 68 ) + rnorm(x ))
180
180
str(mydatC )
181
- if (dev.interactive()) # # visualize:
181
+ if (dev.interactive(TRUE )) # # visualize:
182
182
plot(y ~ x , data = mydatC , col = factor (ch ))
183
183
184
184
Sys.setlocale(" LC_COLLATE" , " C" )
@@ -192,94 +192,49 @@ str(mydatF)
192
192
# # [1] "Component “call”: target, current do not match when deparsed"
193
193
stopifnot(length(ae.cf ) == 1L , grepl(" ^Component .call.:" , ae.cf ))
194
194
195
- Sys.setlocale(" LC_COLLATE" , " de_CH.UTF-8" )
196
- # # but still, summary.lm(fmC) does *not* depend on the locale:
197
- stopifnot(identical(summary(fmCc ), sfmCc ))
198
-
199
- # # data version with de_CH locale --> different level order
200
- mydatF8 <- mydatC ; mydatF8 $ ch <- factor (mydatC $ ch )
201
- str(mydatF8 )
202
- # # $ ch: Factor w/ 7 levels "a","A","b","B",..: 2 4 6 1 3 5 7 2 4 6 ...
203
-
204
- # # "charactor not factor" data -- now different lm() coeff:
205
- (sfmCH8c <- summary(fmCH8c <- lm(y ~ . , data = mydatC )))
206
- # # lm() with *factor* data is the "same"
207
- sfmCH8f <- summary(fmCH8f <- lm(y ~ . , data = mydatF ))
208
- # # ... very similar to the fmCc and fmCf summaries:
209
- stopifnot(all.equal(sfmCH8f , sfmCf ))
210
- (ae8f <- all.equal(sfmCH8f , sfmCc )) # only "call" differs
211
- stopifnot(length(ae8f ) == 1L , grepl(" ^Component .call.:" , ae8f ))
212
-
213
- sfmCH8f8 <- summary(fmCH8f8 <- lm(y ~ . , data = mydatF8 ))
214
- # # as the fmCH8c above :
215
- (aeC8 <- all.equal(sfmCH8f8 , sfmCH8c )) # only "call" ..
216
- stopifnot(length(aeC8 ) == 1L , grepl(" ^Component .call.:" , aeC8 ))
217
-
218
195
coef(fmCc )
219
196
# # (Intercept) x chB chC cha chb chc chd
220
197
# # 12.7781626 19.8494272 -0.8240301 -1.3309157 -31.7032317 -32.8819084 -33.3519985 -34.6249161
221
198
(coef(fmCf ) - > cf.f ) # the same
222
- coef(fmCH8f ) - > cf.8 # same again : factor() was called during "C" locale!
223
199
stopifnot(exprs = {
224
200
identical(coef(fmCc ), cf.f )
225
- identical(cf.f , cf.8 )
226
201
})
227
202
228
- coef(fmCH8c ) # # different, indeed
229
- # # (Intercept) x chA chb chB chc chC chd
230
- # # -18.925069 19.849427 31.703232 -1.178677 30.879202 -1.648767 30.372316 -2.921684
231
-
232
- (dummy.coef(fmCc ) - > df.Cc )
203
+ (dummy.coef(fmCc ) - > dc.Cc ) # #-- was all wrong in R <= 4.3.2
233
204
# # (Intercept): 12.77816
234
205
# # x: 19.84943
235
206
# # ch: A B C a b c d
236
207
# # 0.0000000 -0.8240301 -1.3309157 -31.7032317 -32.8819084 -33.3519985 -34.6249161
237
208
dummy.coef(fmCf ) - > dc.Cf # the same
238
- dummy.coef(fmCH8f ) - > dc.8f # also the same, indeed, typically even identical (not testing):
239
- identical(dc.Cf , dc.8f ) # TRUE
240
209
all.equal15 <- function (x ,y , ... ) all.equal(x ,y , tolerance = 1e-15 , ... )
241
210
stopifnot(exprs = {
242
- all.equal15(dc.Cf , dc.Cf )
243
- all.equal15(dc.Cf , dc.8f )
244
- # # coef() <--> dummy.coef() :
211
+ all.equal15(dc.Cc , dc.Cf ) # *not* in R <= 4.3.2
212
+ # # coef() <--> dummy.coef() {was always true}
245
213
length(dcCf <- unlist(dc.Cf )) == 1 + length(cf.f )
246
214
is.character(names(dcCf ) <- sub(" [.]" , " " , names(dcCf )))
247
215
all.equal15(dcCf [i2 <- 1 : 2 ], cf.f [i2 ], check.attributes = FALSE )
248
216
all.equal15(dcCf [- i2 ], c(chA = 0 , cf.f [- i2 ]))
249
217
})
250
218
251
- dummy.coef(fmCH8c ) # *is* different
252
- # # (Intercept): -18.92507
253
- # # x: 19.84943
254
- # # ch: a A b B c C d
255
- # # 0.000000 31.703232 -1.178677 30.879202 -1.648767 30.372316 -2.921684
256
-
257
219
# #============= + 2 way interactions ============================================
258
- (sfm2c <- summary(fm2c <- lm(y ~ . ^ 2 , data = mydatC )))
259
- sfm2f8 <- summary(fm2f8 <- lm(y ~ . ^ 2 , data = mydatF8 ))
260
- (dc2c <- dummy.coef(fm2c ))
261
- iC <- match(" call" , names(sfm2c ))
262
- all.equal(sfm2c , sfm2f8 )
220
+ fm2c <- lm(y ~ . ^ 2 , data = mydatC )
221
+ cf2c <- coef(fm2c )
222
+ (dc2c <- dummy.coef(fm2c )) # *wrong* in R <= 4.3.2
263
223
stopifnot(exprs = {
264
- all.equal15(sfm2c [- iC ],
265
- sfm2f8 [- iC ])
266
- all.equal15(cf2c <- coef(fm2c ),
267
- coef(fm2f8 ))
268
- all.equal15(dc2c , dummy.coef(fm2f8 ))
269
- length(dc2c <- unlist(dc2c )) == 2 + length(cf2c )
270
-
224
+ length(dc2c <- unlist(dc2c )) == 2 + length(cf2c ) # was false
271
225
all.equal15(dc2c [1 : 2 ], cf2c [1 : 2 ], check.attributes = FALSE )
272
226
is.character(names(dc2c ) <- sub(" [.]" , " " , names(dc2c )))
273
227
all.equal15(dc2c [- (1 : 2 )][1 : 7 ],
274
- c(cha = 0 , cf2c [- (1 : 2 )][1 : 6 ]))
228
+ c(chA = 0 , cf2c [- (1 : 2 )][1 : 6 ]))
275
229
all.equal15(tail(dc2c , 7 ),
276
- c(`x:cha ` = 0 , tail(cf2c , 6 )))
230
+ c(`x:chA ` = 0 , tail(cf2c , 6 )))
277
231
})
278
232
279
- ( sfm2f <- summary( fm2f <- lm(y ~ . ^ 2 , data = mydatF ))) # different
233
+ fm2f <- lm(y ~ . ^ 2 , data = mydatF ) # was always correct
280
234
(dc2f <- dummy.coef(fm2f ))
281
- cf2f <- coef(fm2f )
235
+ cf2f <- coef(fm2f )
282
236
stopifnot(exprs = {
237
+ # # were all TRUE before
283
238
length(dc2f <- unlist(dc2f )) == 2 + length(cf2f )
284
239
all.equal(dc2f [1 : 2 ], cf2f [1 : 2 ], check.attributes = FALSE )
285
240
is.character(names(dc2f ) <- sub(" [.]" , " " , names(dc2f )))
0 commit comments