Re: [R] Problem with systemfit 0.7-3 and transformed variables

From: Arne Henningsen <ahenningsen_at_agric-econ.uni-kiel.de>
Date: Thu 26 May 2005 - 08:49:31 EST

On Wednesday 25 May 2005 18:25, Mikko Pakkanen wrote:
> > We did not notice this shortcoming of systemfit() so far. Unfortunately,
> > I
> > don't have the time in the next few days to look into the code and figure
> > out
> > how to enable transformed variables. I suggest that you either create
> > transformed variables by hand or you modify the systemfit code to enable
> > this
> > and send us the patch. I prefer the second :-) (that's the philosophy of
> > open-source software like R: useRs become developeRs).
>
> Luckily, I had some time to check the code. Debugger revealed that the
> problems are caused by the model.frame function which is used to compile
> the '$data' data frame. I don't need that data frame so much, so I just
> substituted model.frame with model.matrix which apparently doesn't cause
> this error with transformed variables. However, I tuned it a bit further,
> so that it should still return an identical '$data' data frame, despite the
> modification.
> I've only tested this with my example and it appears to be OK. Still, I
> think this should be considered a "quick & dirty" fix -there are probably
> better ways to do it. But, I hope it gives the idea. Here's my attempt:
>
> mikko@briscoe R $ diff -u systemfit.R systemfit-patched.R
> --- systemfit.R 2004-11-26 11:17:36.000000000 +0200
> +++ systemfit-patched.R 2005-05-25 18:55:55.568944699 +0300
> @@ -624,7 +624,11 @@
> Terms <- terms( eqns[[i]], data = data)
> m$formula <- Terms
> m <- eval(m, parent.frame())
> - datai <- model.frame(Terms, m)
> + resp <- model.extract(m, "response")
> + ## using model.matrix instead of model.frame, need to get the
> output variable separately
> + datai <- data.frame(cbind(resp, (model.matrix(Terms, m))[,-1]))
> + ## I guess there's a better way to extract the name of the output
> variable?
> + names(datai)[1] <- as.character(terms(eqns[[i]]))[2]
> if(method=="2SLS" | method=="3SLS") {
> #datai <- cbind( datai, model.frame( instl[[i]] ))
> # the following lines have to be substituted for the previous
> @@ -634,7 +638,8 @@
> Terms <- terms(instl[[i]], data = data)
> m$formula <- Terms
> m <- eval(m, parent.frame())
> - datai <- cbind( datai, model.frame(Terms, m))
> + ## used previously model.frame
> + datai <- cbind( datai, as.data.frame((model.matrix(Terms, m))[,-1]))
> }
>
> if(i==1) {

Thank you very much for the patch. I have uploaded a patched version of systemfit (version 0.7-4) to CRAN. It is also available on my website now:

   http://www.uni-kiel.de/agrarpol/ahenningsen/index-e.html

Best wishes,
Arne

> Regards,
>
> -Mikko.
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

-- 
Arne Henningsen
Department of Agricultural Economics
University of Kiel
Olshausenstr. 40
D-24098 Kiel (Germany)
Tel: +49-431-880 4445
Fax: +49-431-880 1397
ahenningsen@agric-econ.uni-kiel.de
http://www.uni-kiel.de/agrarpol/ahenningsen/

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Thu May 26 08:56:23 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:06 EST