-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Hi everybody,
I open this issue in order to review any problems that I observed with lm function and the package quantiles.
I have reviewed the documentation. Specifically at the following link (https://www.r-spatial.org/r/2018/08/31/quantities-final.html#fitting-linear-models-with-quantities), it is very well specified how to include specific methods to use lm with the package quantities.
First of all, note that this is the first time I have tried to include experimental error in linear regression models. The first question that arises is whether to consider a regression weighing with the uncertainty of the response variable. It is a correct approach?
I have tried to include the weight parameter to the qlm function and it is not able to get the model. The error obtained is the following:
Model_Wc<-qlm(formula = Wcomp ~ Pevap + Pcond + Pevap:Pcond, weights = rep(1, 91), data = df)
Error in eval(extras, data, env) :
..1 usado en un contexto incorreto, ningún ... para examinar
I have reviewed the function definition and this supports additional parameters.
The other problem that I have noticed is the presence of a warning in the coef.qlm function. When the formula to be applied in the function is defined with interaction variables of type x1: x2 (the special nomenclature of th lm function), the following warning is obtained:
> df<-l_scroll$AHRI_66$HPR2A$SH_11
> Model_Wc<-qlm(formula = Wcomp ~ Pevap + Pcond + Pevap:Pcond, data = df)
> coef(Model_Wc)
$`(Intercept)`
0.5(2) [kW]
$Pevap
0.06(2) [kW/bar]
$Pcond
0.34(1) [kW/bar]
$`Pevap:Pcond`
9(10)e-4 [kW]
Warning message:
In mapply(set_quantities, NextMethod(), coef.units, sqrt(diag(vcov(object))), :
el argumento más largo no es múltiplo de la longitud del más corto
On the other hand, If I applied the following definition for the formula parameter the warning disappears:
> Model_Wc<-qlm(formula = Wcomp ~ Pevap + Pcond + I(Pevap*Pcond), data = df)
> coef(Model_Wc)
$`(Intercept)`
0.5(2) [kW]
$Pevap
0.06(2) [kW/bar]
$Pcond
0.34(1) [kW/bar]
$`I(Pevap * Pcond)`
9(10)e-4 [kW/bar^2]
The results seem corrects but a warning is present in the first method.
An other question is about the summary obtained for this qlm objects. If I print the summary the Std. Error of the coefficients is not the same as te previous one (coef(Model_Wc)).
Other problem is how to define the uncertainty for the variables involved in the regression model? Is necessary to define as standard uncertainty or is it possible to define as an expanded uncertainty and to obtaint the correct error for the coefficients when I apply coef function?
Finally, the last question is about the predict function for qlm objects. In the linked reported, it defines specific methods for qlm objects too. I have reviewed the function and it only applies the set_quantities function and it activates the native parameter se.fit. Is the obtained error correct? The se.fit parameter only activates the native confidenze intervals for the lm function. Are not necessary to take into account the experimental uncertainties for the calculation of the response variable error?
This problem is discussed in https://stats.stackexchange.com/questions/235693/linear-model-where-the-data-has-uncertainty-using-r but the final solution involves using the root python packe.
Sorry for the many doubts and thanks in advance