Re: [R] deriv; loop

2007-07-31 Thread Uwe Ligges
francogrex wrote:
 Hi, 2 questions:
 
 Question 1: example of what I currently do:
 
 for(i in 1:6){sink(temp.txt,append=TRUE)
 dput(i+0)
 sink()}
 x=scan(file=temp.txt)
 print(prod(x))
 file.remove(C:/R-2.5.0/temp.txt)
 
 But how to convert the output of the loop to a vector that I can manipulate
 (by prod or sum etc), without having to write and append to a file?


So, do you want the file at the end or not? If not:

x - 1:6
prod(x)

and if this is really the solution you want, the please read the posting 
guide and the manuals before posting again.




 Question 2:
 
 deriv(~gamma(x),x)
 
 expression({
 .expr1 - gamma(x)
 .value - .expr1
 .grad - array(0, c(length(.value), 1), list(NULL, c(x)))
 .grad[, x] - .expr1 * psigamma(x)
 attr(.value, gradient) - .grad
 .value
 })
 
 BUT
 
 deriv3(~gamma(x),x)
 Error in deriv3.formula(~gamma(x), x) : Function 'psigamma' is not in the
 derivatives table
 
 What I want is the expression for the second derivative (which I believe is
 trigamma(x), or psigamma(x,1)), how can I obtain that?


By using some algebraic software (rather than a numeric one) or 
contributing complete derivatives tables for the next R release.

Uwe Ligges

__
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
and provide commented, minimal, self-contained, reproducible code.


[R] deriv; loop

2007-07-30 Thread francogrex

Hi, 2 questions:

Question 1: example of what I currently do:

for(i in 1:6){sink(temp.txt,append=TRUE)
dput(i+0)
sink()}
x=scan(file=temp.txt)
print(prod(x))
file.remove(C:/R-2.5.0/temp.txt)

But how to convert the output of the loop to a vector that I can manipulate
(by prod or sum etc), without having to write and append to a file?

Question 2:

 deriv(~gamma(x),x)

expression({
.expr1 - gamma(x)
.value - .expr1
.grad - array(0, c(length(.value), 1), list(NULL, c(x)))
.grad[, x] - .expr1 * psigamma(x)
attr(.value, gradient) - .grad
.value
})

BUT

 deriv3(~gamma(x),x)
Error in deriv3.formula(~gamma(x), x) : Function 'psigamma' is not in the
derivatives table

What I want is the expression for the second derivative (which I believe is
trigamma(x), or psigamma(x,1)), how can I obtain that?

Thanks
-- 
View this message in context: 
http://www.nabble.com/deriv--loop-tf4166283.html#a11853456
Sent from the R help mailing list archive at Nabble.com.

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] deriv; loop

2007-07-30 Thread jim holtman
for question 1, is this what you want (BTW allocate 'result' to the
size you want - the example keeps extending it which is OK for small
numbers, but for larger size preallocate):

 result - numeric(0)
 for (i in 1:6) result[i] - i
 result
[1] 1 2 3 4 5 6
 prod(result)
[1] 720


On 7/29/07, francogrex [EMAIL PROTECTED] wrote:

 Hi, 2 questions:

 Question 1: example of what I currently do:

 for(i in 1:6){sink(temp.txt,append=TRUE)
 dput(i+0)
 sink()}
 x=scan(file=temp.txt)
 print(prod(x))
 file.remove(C:/R-2.5.0/temp.txt)

 But how to convert the output of the loop to a vector that I can manipulate
 (by prod or sum etc), without having to write and append to a file?

 Question 2:

  deriv(~gamma(x),x)

 expression({
.expr1 - gamma(x)
.value - .expr1
.grad - array(0, c(length(.value), 1), list(NULL, c(x)))
.grad[, x] - .expr1 * psigamma(x)
attr(.value, gradient) - .grad
.value
 })

 BUT

  deriv3(~gamma(x),x)
 Error in deriv3.formula(~gamma(x), x) : Function 'psigamma' is not in the
 derivatives table

 What I want is the expression for the second derivative (which I believe is
 trigamma(x), or psigamma(x,1)), how can I obtain that?

 Thanks
 --
 View this message in context: 
 http://www.nabble.com/deriv--loop-tf4166283.html#a11853456
 Sent from the R help mailing list archive at Nabble.com.

 __
 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
 and provide commented, minimal, self-contained, reproducible code.



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

__
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
and provide commented, minimal, self-contained, reproducible code.