mloop / lodr

R package for analyzing covariates subject to a limit of detection
Other
0 stars 0 forks source link

Create main function lm_lod #4

Closed mloop closed 5 years ago

mloop commented 5 years ago

This function should produce an lm type object

mloop commented 5 years ago

@mloop ,

There is one issue that I have run into with returning an lm/glm object. Neither a lm or glm object store the coefficient estimate standard errors. Instead, these are calculated from the lm object when calling a corresponding function on the lm object (for example summary). The lm object is constructed to include all elements required to calculate the standard errors when the corresponding function is called (the X matrix, etc.).

This poses a problem for us since we use a completely method for calculating the standard errors, one which does not use any of the components traditionally used for a lm object (the bootstrap code).

Using a glm object type poses as the same problem (as they use iteratively re-weighted least squares, which again has a corresponding formula for the standard errors involving the X matrix).

One option is that we return the output as an lm object, and then write a new summary function which is identical to the summary.lm function but runs the bootstrap method and rewrites the default SEs from the lm object with the bootstrap SEs (though this doesn't seem very elegant to me).

mloop commented 5 years ago

@kmdono02 One elegant way to handle this would be to create a new class, say lm.lod, and then assign the object to have class lm and class lm.lod. Then, you could write a method called summary.lod, which would look almost identical to the summary.lm function but appropriately use the bootstrap standard errors.

I would approach this function by having the default behavior be the bootstrap. So, when someone calls something like

fit <- lm_lod(y ~ x1 + x2 + x3, lod_vars = c("x1"), data = data)

the procedure would automatically run the bootstrap and return an object of type lm and lm.lod. When someone runs summary(fit), that should call summary.lm.lod(fit) and not summary.lm(fit).

kmdono02 commented 5 years ago

This has been completed, see updated repo. I called it lod_regression (though I will change this, so I'll leave this open).

kmdono02 commented 5 years ago

Changed function name to lod_lm, I'll now close this.