The comments are getting a bit unwieldy, so here's a summary and some further suggestions.
To re-iterate, can you please make sure that
- you are starting from a fresh R terminal,
- there are no objects in your global environment (from e.g. loading your local
.Rprofile
); to debug this case, ideally .Rprofile
should be empty; and
- you are not resuming a previous R session.
Provided you did the above, ls()
should not return anything, and functions like lm
should refer to the base R functions.
If you still get different results, perhaps try calculating the OLS estimates manually
X <- model.matrix(Sepal.Length ~ Sepal.Width + as.factor(Species), data = iris)
y <- with(iris, Sepal.Length)
R <- t(X) %*% X
solve(R) %*% t(X) %*% y
# [,1]
#(Intercept) 2.2513932
#Sepal.Width 0.8035609
#as.factor(Species)versicolor 1.4587431
#as.factor(Species)virginica 1.9468166
Compare with the lm
estimates
coef(lm(Sepal.Length ~ Sepal.Width + Species, data = iris))
#(Intercept) Sepal.Width Speciesversicolor Speciesvirginica
# 2.2513932 0.8035609 1.4587431 1.9468166
If results are different, I'd suggest stepping through the manual OLS estimate calculation and compare e.g. the X
and R
objects on both machines.
Update
I have installed Solus (Budgie) 4.0 Fortitude in a VM, and lm
gives the correct results
coef(lm(Sepal.Length ~ Sepal.Width + Species, data = iris))
#(Intercept) Sepal.Width Speciesversicolor Speciesvirginica
# 2.2513932 0.8035609 1.4587431 1.9468166
Details involving the OS
uname -r
#5.3.10-134.current
gcc --version | head -n 1
#gcc (Solus) 9.2.0
inxi -Fz
#System: Host: solus Kernel: 5.3.10-134.current x86_64 bits: 64 Desktop: Budgie 10.5.1 Distro: Solus 4.0
#Machine: Type: Virtualbox System: innotek product: VirtualBox v: 1.2 serial: <filter>
# Mobo: Oracle model: VirtualBox v: 1.2 serial: <filter> BIOS: innotek v: VirtualBox date: 12/01/2006
#CPU: Topology: Single Core model: Intel Core i5-6600 bits: 64 type: MCP L2 cache: 6144 KiB
# Speed: 3312 MHz min/max: N/A Core speed (MHz): 1: 3312
#Graphics: Device-1: VMware SVGA II Adapter driver: vmwgfx v: 2.15.0.0
# Display: x11 server: X.Org 1.20.5 driver: vmware unloaded: fbdev,modesetting,vesa resolution: 2560x1440~60Hz
# OpenGL: renderer: llvmpipe (LLVM 9.0 256 bits) v: 3.3 Mesa 19.2.5
#Audio: Device-1: Intel 82801AA AC97 Audio driver: snd_intel8x0
# Sound Server: ALSA v: k5.3.10-134.current
#Network: Device-1: Intel 82540EM Gigabit Ethernet driver: e1000
# IF: enp0s3 state: up speed: 1000 Mbps duplex: full mac: <filter>
# Device-2: Intel 82371AB/EB/MB PIIX4 ACPI type: network bridge driver: piix4_smbus
#Drives: Local Storage: total: 40.00 GiB used: 7.33 GiB (18.3%)
# ID-1: /dev/sda vendor: VirtualBox model: VBOX HARDDISK size: 40.00 GiB
#Partition: ID-1: / size: 18.36 GiB used: 7.25 GiB (39.5%) fs: ext4 dev: /dev/dm-1
# ID-2: /boot size: 269.0 MiB used: 83.7 MiB (31.1%) fs: ext4 dev: /dev/sda1
# ID-3: swap-1 size: 956.0 MiB used: 0 KiB (0.0%) fs: swap dev: /dev/dm-0
#Sensors: Message: No sensors data was found. Is sensors configured?
#Info: Processes: 159 Uptime: 21h 57m Memory: 3.84 GiB used: 579.1 MiB (14.7%) #Shell: bash inxi: 3.0.36