An embedded and charset-unspecified text was scrubbed... Name: no disponible URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121101/dbd19378/attachment.pl>
Problem with lm
12 messages · Eva Prieto Castro, Jorge I Velez, Greg Snow +4 more
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121101/1fcfd422/attachment.pl>
Yes, it is most likely due to scoping. It is safest to create a data frame with all the data in it, then pass that to the data argument of lm.
On Thu, Nov 1, 2012 at 2:25 AM, Eva Prieto Castro <evapcastro at yahoo.es> wrote:
Hi,
I have a problem in relation with a packahe I made. It runs on my machine (Windows, where I made the package), and it runs in a Mac machine, but it does not run in another Mac machine with the same R version.
The part of the code is giving problems:
singleCosinor <- function(t, y, period=24) {
x1 <- cos(2 * pi * t / period)
x2 <- sin(2 * pi * t / period)
single <- lm (y ~ x1 + x2)
return(single)
}
The error:
Error en eval(expr, envir, enclos) : objeto 'y' no encontrado
Can it be in relation with scoping?.
Thanks in advance.
Eva
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
But the 'y' is a parameter to the function, so does this mean that the error is occurring when the function is invoked without that parameter?
On 1 November 2012 16:02, Greg Snow <538280 at gmail.com> wrote:
Yes, it is most likely due to scoping. It is safest to create a data frame with all the data in it, then pass that to the data argument of lm. On Thu, Nov 1, 2012 at 2:25 AM, Eva Prieto Castro <evapcastro at yahoo.es> wrote:
Hi,
I have a problem in relation with a packahe I made. It runs on my machine (Windows, where I made the package), and it runs in a Mac machine, but it does not run in another Mac machine with the same R version.
The part of the code is giving problems:
singleCosinor <- function(t, y, period=24) {
x1 <- cos(2 * pi * t / period)
x2 <- sin(2 * pi * t / period)
single <- lm (y ~ x1 + x2)
return(single)
}
The error:
Error en eval(expr, envir, enclos) : objeto 'y' no encontrado
Can it be in relation with scoping?.
Thanks in advance.
Eva
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Mick Cooney mickcooney at gmail.com
This error can still occur even if something is passed as the y parameter to the function. There are several things that can complicate the process (and I don't remember exactly which one causes the problem in this case). Here are a couple: In the original function, y is a parameter, but it is never actually used before the call to lm, which means that y is really a promise to evaluate whatever was passed to the function, but does not yet contain the actual y values. The lm function calls the model.frame function which calls the model.frame.default function, which may call another function, which of all those function environments should it look for the variable y in? (it seems obvious to us, but the computer is not as smart), there is also the environment that the formula was defined in that is used for some things. Possibly others as well. In either case if an explicit data frame is created (which will force the evaluation of the promise for y) and passed to the data argument of lm, then all these functions know exactly where to look to find the variables in the formula and don't need to worry about parent frames and parent environments. This document: http://developer.r-project.org/nonstandard-eval.pdf gives more detail.
On Thu, Nov 1, 2012 at 10:23 AM, Mick Cooney <mickcooney at gmail.com> wrote:
But the 'y' is a parameter to the function, so does this mean that the error is occurring when the function is invoked without that parameter? On 1 November 2012 16:02, Greg Snow <538280 at gmail.com> wrote:
Yes, it is most likely due to scoping. It is safest to create a data frame with all the data in it, then pass that to the data argument of lm. On Thu, Nov 1, 2012 at 2:25 AM, Eva Prieto Castro <evapcastro at yahoo.es> wrote:
Hi,
I have a problem in relation with a packahe I made. It runs on my machine (Windows, where I made the package), and it runs in a Mac machine, but it does not run in another Mac machine with the same R version.
The part of the code is giving problems:
singleCosinor <- function(t, y, period=24) {
x1 <- cos(2 * pi * t / period)
x2 <- sin(2 * pi * t / period)
single <- lm (y ~ x1 + x2)
return(single)
}
The error:
Error en eval(expr, envir, enclos) : objeto 'y' no encontrado
Can it be in relation with scoping?.
Thanks in advance.
Eva
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
-- Mick Cooney mickcooney at gmail.com
Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
See comments inline
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of Mick Cooney Sent: Thursday, November 01, 2012 9:23 AM To: Greg Snow Cc: r-help at r-project.org; Eva Prieto Castro Subject: Re: [R] Problem with lm But the 'y' is a parameter to the function, so does this mean that the error is occurring when the function is invoked without that parameter?
We haven't seen the actual call to the function, singleCosinor(), in your code so we can't say for sure what the problem is. However, the confusion may be that while there is a formal parameter named y, it does not refer to any variable named y in the global environment. If you have a variables t and y in the global environment, then the call would need to be singleCosinor(t=t, y=y) hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204
On 1 November 2012 16:02, Greg Snow <538280 at gmail.com> wrote:
Yes, it is most likely due to scoping. It is safest to create a data frame with all the data in it, then pass that to the data argument of lm. On Thu, Nov 1, 2012 at 2:25 AM, Eva Prieto Castro
<evapcastro at yahoo.es> wrote:
Hi, I have a problem in relation with a packahe I made. It runs on my
machine (Windows, where I made the package), and it runs in a Mac machine, but it does not run in another Mac machine with the same R version.
The part of the code is giving problems:
singleCosinor <- function(t, y, period=24) {
x1 <- cos(2 * pi * t / period)
x2 <- sin(2 * pi * t / period)
single <- lm (y ~ x1 + x2)
return(single)
}
The error:
Error en eval(expr, envir, enclos) : objeto 'y' no encontrado
Can it be in relation with scoping?.
Thanks in advance.
Eva
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-
guide.html
and provide commented, minimal, self-contained, reproducible code.
-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
An embedded and charset-unspecified text was scrubbed... Name: no disponible URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121101/4cf7c8b1/attachment.pl>
Did you ever show us the call to your function that made it fail on one machine and succeed on two others? In addition, seeing the output of traceback() after the failure and the output of sessionInfo() and conflicts() would help track down the problem. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Eva Prieto Castro Sent: Thursday, November 01, 2012 2:59 PM To: Mick Cooney; Greg Snow Cc: r-help at r-project.org Subject: Re: [R] Problem with lm Thanks, Mick and Greg. Greg, I? have one doubt: taking into account that scope is the cause and that I need to pass a data.frame in the data of the lm, why does it run in some machines?. That point is the one I do not understand. In any case, I made the change (data.frame) and it will be tested. Cheers, Eva --- El jue, 1/11/12, Greg Snow <538280 at gmail.com> escribi?: De: Greg Snow <538280 at gmail.com> Asunto: Re: [R] Problem with lm Para: "Mick Cooney" <mickcooney at gmail.com> CC: "Eva Prieto Castro" <evapcastro at yahoo.es>, r-help at r-project.org Fecha: jueves, 1 de noviembre, 2012 17:49 This error can still occur even if something is passed as the y parameter to the function.? There are several things that can complicate the process (and I don't remember exactly which one causes the problem in this case).? Here are a couple: In the original function, y is a parameter, but it is never actually used before the call to lm, which means that y is really a promise to evaluate whatever was passed to the function, but does not yet contain the actual y values. The lm function calls the model.frame function which calls the model.frame.default function, which may call another function, which of all those function environments should it look for the variable y in?? (it seems obvious to us, but the computer is not as smart), there is also the environment that the formula was defined in that is used for some things. Possibly others as well. In either case if an explicit data frame is created (which will force the evaluation of the promise for y) and passed to the data argument of lm, then all these functions know exactly where to look to find the variables in the formula and don't need to worry about parent frames and parent environments. This document: http://developer.r-project.org/nonstandard-eval.pdf gives more detail. On Thu, Nov 1, 2012 at 10:23 AM, Mick Cooney <mickcooney at gmail.com> wrote:
But the 'y' is a parameter to the function, so does this mean that the error is occurring when the function is invoked without that parameter? On 1 November 2012 16:02, Greg Snow <538280 at gmail.com> wrote:
Yes, it is most likely due to scoping.? It is safest to create a data frame with all the data in it, then pass that to the data argument of lm. On Thu, Nov 1, 2012 at 2:25 AM, Eva Prieto Castro <evapcastro at yahoo.es> wrote:
Hi, I have a problem in relation with a packahe I made. It runs on my machine (Windows,
where I made the package), and it runs in a Mac machine, but it does not run in another Mac machine with the same R version.
The part of the code is giving problems:
singleCosinor <- function(t, y, period=24) {
???x1 <- cos(2 * pi * t / period)
???x2 <- sin(2 * pi * t / period)
???single <- lm (y ~ x1 + x2)
???return(single)
}
The error:
Error en eval(expr, envir, enclos) : objeto 'y' no encontrado
Can it be in relation with scoping?.
Thanks in advance.
Eva
? ? ? ???[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
-- Mick Cooney mickcooney at gmail.com
-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com [[alternative HTML version deleted]]
An embedded and charset-unspecified text was scrubbed... Name: no disponible URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121102/4ef9df1f/attachment.pl>
3 days later
An embedded and charset-unspecified text was scrubbed... Name: no disponible URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121105/f0205543/attachment.pl>
On 06/11/12 05:20, Eva Prieto Castro wrote:
Hi,
I solved as follws:
? f <- formula(y ~ x1 + x2)
? single <- do.call("lm", list(f, data=mydf))
It works in every machine!!.
Well, if you are happy with the result, I guess that can't be argued with.
However the fact that your previous attempts worked on some machines
and not on others indicates to me that something fundamentally wrong
is going on somewhere. If it were *my* package I'd want to track it down,
figure out exactly why this anomaly was happening, and fix it from an
informed point of view. Just trying things more or less at random until
something works is not a good strategy for writing robust and reliable
code.
It seems to me that resorting to the use of do.call() should not be
necessary,
and it is not at all clear to me why this should help with the "no
encontrado"
problem anyway.
cheers,
Rolf
An embedded and charset-unspecified text was scrubbed... Name: no disponible URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121106/b6c4a1db/attachment.pl>