<!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 &lt;- function(formula, data, itercrit=10,devcrit=0.0001)
<br>{
<br>#
<br># Init step
<br>#
<br>init &lt;- glm(formula=formula,family=gaussian, data=data)
<br>response &lt;- resid(init,type="response") + predict(init,type="response")
<br>mu &lt;- predict(init,type="response")
<br>iter &lt;- 1
<br>dev &lt;- init$deviance
<br>if (dev != 0) vardev &lt;- 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 &lt;= itercrit)| (vardev > devcrit)) {
<br>d_(response - mu)^2
<br>modvar_glm(formula=formulavar,family=Gamma(link=log),data=data)
<br>sig &lt;- predict(modvar,type="response")
<br>weights &lt;- 1/sig
<br>modesp &lt;- glm(formula=formula, family=gaussian,data=data,weights=weights)
<br>mu &lt;- predict(modesp,type="response")
<br>devold &lt;- dev
<br>dev &lt;- modesp$deviance
<br>vardev &lt;- (devold -dev)/devold
<br>iter &lt;- 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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; modesp &lt;- 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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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>&nbsp;
<br>&nbsp;
<br>&nbsp;
<br>&nbsp;
<br>&nbsp;
<pre>--&nbsp;
Isabelle Zabalza-Mezghani&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tel : 01 47 52 61 99
Institut Fran&ccedil;ais du P&eacute;trole&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; E-mail : isabelle.zabalza-mezghani@ifp.fr
1-4 Av. Bois Preau - Bat Lauriers
92852 Rueil Malmaison Cedex, France</pre>
&nbsp;</html>