Re: [R] Replicate Excel's LOGEST worksheet function in R

2010-11-15 Thread cran . 30 . miller_2555
On Sat, Nov 13, 2010 at 10:37 PM, Jeff Newmiller - jdnew...@dcn.davis.ca.us
<+cran+miller_2555+a7f4a7aeab.jdnewmil#dcn.davis.ca...@spamgourmet.com>wrote:

>
> Anyway, I recommend you learn from David before criticizing his assistance.
>
>   >On Fri, Nov 12, 2010 at 5:28 PM,
> David Winsemius -
> >dwinsem...@comcast.net
> ><+cran+miller_2555+c0e7477398.dwinsemius#comcast@spamgourmet.com>
> >wrote:
> > Then WHY did you ask for a function that would duplicate a particular
> Excel function? ... especially an Excel function which DOES a linear fit
> on the log of the Y argument?


It was not a critical response. It was a clarification with the solution
that fit my issue. In fact, David was directionally helpful in solving the
issue. I am neither a statistician nor well versed in the computational
nuance of Excel functions. In the future, I will refrain from such
clarifying posts to avoid inflammatory ones.

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Replicate Excel's LOGEST worksheet function in R

2010-11-13 Thread cran . 30 . miller_2555

On Nov 13, 2010, at 10:12 PM, cran.30.miller_2...@spamgourmet.com wrote:

> On Fri, Nov 12, 2010 at 5:28 PM, David Winsemius - 
> cran.30.miller_2...@spamgourmet.com 
>  <+cran 
> +miller_2555+c0e7477398.dwinsemius#comcast@spamgourmet.com> wrote:
>
> On Nov 12, 2010, at 5:07 PM, David Winsemius wrote:
>
>
> On Nov 12, 2010, at 4:22 PM, cran.30.miller_2...@spamgourmet.com  
> wrote:
>
> Hi -
>
>   I have a dataframe of (x,y) values. I'd like to fit an exponential
> curve to the data for further statistical analysis (pretty much the  
> same
> functionality provided by Excel's LOGEST worksheet array function).  
> Can
> someone point me to the (set of) functions/ package that is best  
> suited to
> provide this functionality? Admittedly, I am a novice in the use of R
> statistical functions, so a brief example of how to compute a  
> correlation
> coefficient off a fitted exponential curve would be greatly  
> appreciated
> (though I could probably work through it over time if I knew the  
> proper R
> tools).
>
>
> Probably (not seeing a clear description of the LOGEST function):
>
> ?exp
> ?log
> ?lm
> ?cor
>
>
> I set up a OO.org Calc spreadsheet which has a lot of Excel work- 
> alike functions and does have a LOGEST. Giving an argument of x=1:26  
> and y=exp(x) to the first two arguments of LOGEST, I get 1 and e.  
> The OO.org help page says
> "FunctionType (optional). If Function_Type = 0, functions in the  
> form y = m^x will be calculated. Otherwise, y = b*m^x functions will  
> be calculated."
>
> This might be the equivalent R operation:
>
> > x<-1:26
> > y<-exp(x)
> > lm(log(y) ~ x)
>
> Call:
> lm(formula = log(y) ~ x)
>
> Coefficients:
> (Intercept)x
>  01
>
> > exp(coef(lm(log(y) ~ x)))
> (Intercept)   x
>   1.002.718282
>
> Note this is not a correlation coefficient but rather an  
> (exponentiated) regression coefficient.
>
> -- 
> David Winsemius, MD
> West Hartford, CT
>
>
>
> Thanks, but I'm looking to fit an exponential curve (not a linear  
> model).


Then WHY did you ask for a function that would duplicate a particular  
Excel function? ... especially an Excel function which DOES a  
linear fit on the log of the Y argument?

http://support.microsoft.com/kb/828528

> However, I was able to identify the `nls()` function that works well  
> (adapted from John Fox's contribution "Nonlinear Regression and  
> Nonlinear Least Squares" [Jan 2002] ref: 
> http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-nonlinear-regression.pdf)
>  
> . For those interested, the following short script highlights my  
> simple test case (though a little sloppy):
>
> mydf <- as.data.frame(cbind(1:6,rev(c(48., 24., 12.,  
> 6., 3., 1.5000)),rev(c( 51.4943, 12.4048, 12.9587, 3.7707,  
> 2.4253, 2.0400;
> colnames(mydf) <- c("X","Y","Y2");
>
> my.mod <- nls(Y2 ~ a*exp(b*X), data=mydf, start=list(a=3.00,b=2.00),  
> trace=T)
>
> plot(mydf[,"X"],residuals(my.mod))
> plot(mydf[,"X"],mydf[,"Y2"], lwd=1)
> lines(mydf[,"X"],fitted.values(my.mod), lwd=2)
>

David Winsemius, MD
West Hartford, CT


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Replicate Excel's LOGEST worksheet function in R

2010-11-13 Thread cran . 30 . miller_2555
On Fri, Nov 12, 2010 at 5:28 PM, David Winsemius - dwinsem...@comcast.net
<+cran+miller_2555+c0e7477398.dwinsemius#comcast@spamgourmet.com> wrote:

>
> On Nov 12, 2010, at 5:07 PM, David Winsemius wrote:
>
>
>> On Nov 12, 2010, at 4:22 PM, cran.30.miller_2...@spamgourmet.com wrote:
>>
>>  Hi -
>>>
>>>   I have a dataframe of (x,y) values. I'd like to fit an exponential
>>> curve to the data for further statistical analysis (pretty much the same
>>> functionality provided by Excel's LOGEST worksheet array function). Can
>>> someone point me to the (set of) functions/ package that is best suited
>>> to
>>> provide this functionality? Admittedly, I am a novice in the use of R
>>> statistical functions, so a brief example of how to compute a correlation
>>> coefficient off a fitted exponential curve would be greatly appreciated
>>> (though I could probably work through it over time if I knew the proper R
>>> tools).
>>>
>>>
>> Probably (not seeing a clear description of the LOGEST function):
>>
>> ?exp
>> ?log
>> ?lm
>> ?cor
>>
>>
> I set up a OO.org Calc spreadsheet which has a lot of Excel work-alike
> functions and does have a LOGEST. Giving an argument of x=1:26 and y=exp(x)
> to the first two arguments of LOGEST, I get 1 and e. The OO.org help page
> says
> "FunctionType (optional). If Function_Type = 0, functions in the form y =
> m^x will be calculated. Otherwise, y = b*m^x functions will be calculated."
>
> This might be the equivalent R operation:
>
> > x<-1:26
> > y<-exp(x)
> > lm(log(y) ~ x)
>
> Call:
> lm(formula = log(y) ~ x)
>
> Coefficients:
> (Intercept)x
>  01
>
> > exp(coef(lm(log(y) ~ x)))
> (Intercept)   x
>   1.002.718282
>
> Note this is not a correlation coefficient but rather an (exponentiated)
> regression coefficient.
>
> --
> David Winsemius, MD
> West Hartford, CT
>
>
>
Thanks, but I'm looking to fit an exponential curve (not a linear model).
However, I was able to identify the `nls()` function that works well
(adapted from John Fox's contribution "Nonlinear Regression and Nonlinear
Least 
Squares"
[Jan 2002] ref:
http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-nonlinear-regression.pdf).
For those interested, the following short script highlights my simple test
case (though a little sloppy):

mydf <- as.data.frame(cbind(1:6,rev(c(48., 24., 12., 6.,
3., 1.5000)),rev(c( 51.4943, 12.4048, 12.9587, 3.7707, 2.4253,
2.0400;
colnames(mydf) <- c("X","Y","Y2");

my.mod <- nls(Y2 ~ a*exp(b*X), data=mydf, start=list(a=3.00,b=2.00),
trace=T)

plot(mydf[,"X"],residuals(my.mod))
plot(mydf[,"X"],mydf[,"Y2"], lwd=1)
lines(mydf[,"X"],fitted.values(my.mod), lwd=2)

[[alternative HTML version deleted]]

__
R-help@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.


[R] Replicate Excel's LOGEST worksheet function in R

2010-11-12 Thread cran . 30 . miller_2555
Hi -

 I have a dataframe of (x,y) values. I'd like to fit an exponential
curve to the data for further statistical analysis (pretty much the same
functionality provided by Excel's LOGEST worksheet array function). Can
someone point me to the (set of) functions/ package that is best suited to
provide this functionality? Admittedly, I am a novice in the use of R
statistical functions, so a brief example of how to compute a correlation
coefficient off a fitted exponential curve would be greatly appreciated
(though I could probably work through it over time if I knew the proper R
tools).

Thanks -
Will

[[alternative HTML version deleted]]

__
R-help@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.