<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hello,
<p>I am try to perform a modeling which is relevant in a strongly heteroscedastic
context.
<br>So I perform a dual modeling (modeling of both mean and variance of
a response) in using the following loop:
<p>jointmod <- function(formula, data, itercrit=10,devcrit=0.0001)
<br>{
<br>#
<br># Init step
<br>#
<br>init <- glm(formula=formula,family=gaussian, data=data)
<br>response <- resid(init,type="response") + predict(init,type="response")
<br>mu <- predict(init,type="response")
<br>iter <- 1
<br>dev <- init$deviance
<br>if (dev != 0) vardev <- 1
<br>else stop(message="Null deviance in initialisation step")
<br>endformula_ strsplit(formula,"~")[[3]]
<br>formulavar_paste("d","~")
<br>formulavar_as.formula(paste(formulavar,endformula))
<br>#
<br># Modeling loop
<br>#
<br>while ((iter <= itercrit)| (vardev > devcrit)) {
<br>d_(response - mu)^2
<br>modvar_glm(formula=formulavar,family=Gamma(link=log),data=data)
<br>sig <- predict(modvar,type="response")
<br>weights <- 1/sig
<br>modesp <- glm(formula=formula, family=gaussian,data=data,weights=weights)
<br>mu <- predict(modesp,type="response")
<br>devold <- dev
<br>dev <- modesp$deviance
<br>vardev <- (devold -dev)/devold
<br>iter <- iter + 1
<br>}
<p>list(modesp=modesp, modvar=modvar, iter=iter, vardev=vardev)
<br>}
<p>This program evaluation always stops when evaluating the "modesp" line
:
<br> modesp <- glm(formula=formula,
family=gaussian,data=data,weights=weights)
<br>with the following error:
<br>error in model.frame(formula,rownames,variables,varnames,extras,extranames,
:
<br> invalid
variable type.
<p>The same program without specifying weights runs.
<br>I don't understand this behavior since when I execute the glm command
with weights out of the program, it runs.
<p>I run R1.3.0 under Windows.
<p>If someone can help me ...
<p>Isabelle Zabalza-Mezghani
<br>
<br>
<br>
<br>
<br>
<pre>--
Isabelle Zabalza-Mezghani Tel : 01 47 52 61 99
Institut Français du Pétrole E-mail : isabelle.zabalza-mezghani@ifp.fr
1-4 Av. Bois Preau - Bat Lauriers
92852 Rueil Malmaison Cedex, France</pre>
</html>