similar to: Integrate a 1-variable function with 1 parameter (Jose L. Romero)

Displaying 20 results from an estimated 6000 matches similar to: "Integrate a 1-variable function with 1 parameter (Jose L. Romero)"

2004 Jul 03
4
counting the occurrences of vectors
Hi: I have two matrices, A and B, where A is n x k, and B is m x k, where n >> m >> k. Is there a computationally fast way to count the number of times each row (a k-vector) of B occurs in A? Thanks for any suggestions. Best, Ravi. [[alternative HTML version deleted]]
2009 Nov 02
2
a prolem with constrOptim
Hi, I apologize for the long message but the problem I encountered can't be stated in a few lines. I am having some problems with the function constrOptim. My goal is to maximize the likelihood of product of K multinomials, each with four catagories under linear constraints on the parameter values. I have found that the function does not work for many data configurations. #The likelihood
2007 Feb 08
2
Timings of function execution in R [was Re: R in Industry]
On 2/8/07, Albrecht, Dr. Stefan (AZ Private Equity Partner) <stefan.albrecht at apep.com> wrote: > Dear all, > > Thanks a lot for your comments. > > I very well agree with you that writing efficient code is about optimisation. The most important rules I know would be: > - vectorization > - pre-definition of vectors, etc. > - use matrix instead of data.frame > - do
2008 Aug 15
1
Vectorization of duration of the game in the gambler ruin's problem
Hey fellas: In the context of the gambler's ruin problem, the following R code obtains the mean duration of the game, in turns: # total.capital is a constant, an arbitrary positive integer # initial.capital is a constant, an arbitrary positive integer between, and not including # 0 and total.capital # p is the probability of winning 1$ on each turn # 1-p is the probability of loosing 1$ # N
2008 Mar 07
3
Numerical Integration in 1D
Dear UseRs, I'm curious about the derivative of n!. We know that Gamma(n+1)=n! So when on takes the derivative of Gamma(n+1) we get Int(ln(x)*exp(-x)*x^n,x=0..Inf). I've tried code like > integrand<-function(x) {log(x)*exp(x)*x^n} > integrate(integrand,lower=0,upper=Inf) It seems that R doesn't like to integrate for any n, and I was wondering if anyone knew a way around
2011 Nov 10
2
performance of adaptIntegrate vs. integrate
Dear list, [cross-posting from Stack Overflow where this question has remained unanswered for two weeks] I'd like to perform a numerical integration in one dimension, I = int_a^b f(x) dx where the integrand f: x in IR -> f(x) in IR^p is vector-valued. integrate() only allows scalar integrands, thus I would need to call it many (p=200 typically) times, which sounds suboptimal. The
2009 Dec 08
4
lower.tail option in pnorm
Hi, I would have thought that these two constructions would produce the same result but they do not. Resp <- rbinom(10, 1, 0.5) Stim <- rep(0:1, 5) mm <- model.matrix(~ Stim) Xb <- mm %*% c(0, 1) ifelse(Resp, log(pnorm(Xb)), log(1 - pnorm(Xb))) pnorm(as.vector(Xb), lower.tail = Resp, log.p = TRUE) > ifelse(Resp, log(pnorm(Xb)), log(1 - pnorm(Xb))) [1] -0.6931472 -1.8410216
2008 Aug 26
2
Problem with Integrate for NEF-HS distribution
I need to calcuate the cumulative probability for the Natural Exponential Family - Hyperbolic secant distribution with a parameter theta between -pi/2 and pi/2. The integration should be between 0 and 1 as it is a probability. The function "integrate" works fine when the absolute value of theta is not too large. That is, the NEF-HS distribution is not too skewed. However, once the
2011 Mar 29
5
Integration with variable bounds
If this is posted elsewhere I cannot find it. I need to perform multiple integration where some of the variables are in the bounds of the other variables. I was trying to use R2Cuba function but cannot set the upper and lower bounds. My code so far is : int <- function(y){ u2 = y[1] z2 = y[2] u1 =y[3] z1 = y[4] ff <- u1*(z1-u1)*u2*(z2-u2)*exp(-0.027*(12-z2)) return(ff) }
2011 Sep 02
5
Hessian Matrix Issue
Dear All, I am running a simulation to obtain coverage probability of Wald type confidence intervals for my parameter d in a function of two parameters (mu,d). I am optimizing it using "optim" method "L-BFGS-B" to obtain MLE. As, I want to invert the Hessian matrix to get Standard errors of the two parameter estimates. However, my Hessian matrix at times becomes
2010 Dec 15
5
Solution to differential equation
Hello, I am trying to find the analytical solution to this differential equation dR/dt = k1*(R^k2)*(1-(R/Rmax)); R(0) = Ro k1 and k2 are parameters that need to fitted, while Ro and Rmax are the baseline and max value (which can be fitted or fixed). The response (R) increases initially at an exponential rate governed by the rate constants k1 and k2. Response has a S-shaped curve as a function
2010 Dec 06
3
0.5 != integrate(dnorm,0,20000) = 0
Hello: The example "integrate(dnorm,0,20000)" says it "fails on many systems". I just got 0 from it, when I should have gotten either an error or something close to 0.5. I got this with R 2.12.0 under both Windows Vista_x64 and Linux (Fedora 13); see the results from Windows below. I thought you might want to know. Thanks for all your work in creating
2007 Dec 17
3
integration
Dear All, I need to perform a numerical integration of one dimensional fucntions. The extrems of integration are both finite and the functions I'm working on are quite complicated. I have already tried both area() and integrate(), but they do not perform well: area() is very slow and integrate() does not converge. Are in R other functions for numerical integration of one dimentional
2012 Aug 04
3
Head or Tails game
Hi, Reading about a "Heads and Tails" game in http://www.dartmouth.edu/~chance/teaching_aids/books_articles/probability_book/amsbook.mac.pdf Introduction to Probability (Example 1.4, pp. 5-8). You toss a coin 40 times. If heads, Peter wins $1, tails, he loses $1. I think I can do that ok with: winnings <- sum(sample(c(-1,1), 40, replace=TRUE)) But I have to do it 10,000 times
2009 Jul 17
6
Solving two nonlinear equations with two knowns
Dear R users, I have two nonlinear equations, f1(x1,x2)=0 and f2(x1,x2)=0. I try to use optim command by minimize f1^2+f2^2 to find x1 and x2. I found the optimal solution changes when I change initial values. How to solve this? BTW, I also try to use grid searching. But I have no information on ranges of x1 and x2, respectively. Any suggestion to solve this question? Thanks, Kate
2010 Dec 15
3
Applying function to a TABLE and also "apply, tapply, sapply etc"
Dear R-help forum members, Suppose I have a data-frame having two variables and single data for each of them, as described below. variable_1           variable_2         10                          20 I have written a function, say, 'fun' which uses input 10 and 20 and gives me desired result. fun = function(X, Y)          {          X + Y              #( I am just giving an example of
2010 Jun 29
1
Performance enhancement for ave
library(plyr) n<-100000 grp1<-sample(1:750, n, replace=T) grp2<-sample(1:750, n, replace=T) d<-data.frame(x=rnorm(n), y=rnorm(n), grp1=grp1, grp2=grp2) system.time({ d$avx1 <- ave(d$x, list(d$grp1, d$grp2)) d$avy1 <- ave(d$y, list(d$grp1, d$grp2)) }) # user system elapsed # 39.300 0.279 40.809 system.time({ d$avx2 <- ave(d$x, interaction(d$grp1, d$grp2, drop =
2011 May 03
2
adaptIntegrate - how to pass additional parameters to the integrand
Hello, I am trying to use adaptIntegrate function but I need to pass on a few additional parameters to the integrand. However, this function seems not to have the flexibility of passing on such additional parameters. Am I missing something or this is a known limitation. Is there a good alternative to such restrictions, if there at all are? Many thanks for your time. HC -- View this message in
2010 Feb 12
3
summary statistics for grouped data
Hello list: Is there an easy way (preferably through one of the standard R packages) of obtaining summary statistics for grouped data? I could split the data into classes by hist, and then progressively calculate all the "columns" i need to obtain the mean and standard deviation, but i was looking for a single function that could do that with a data vector. Thanks in advance, jose
2009 Apr 03
2
Geometric Brownian Motion Process with Jumps
Hi, I have been using maxLik to do some MLE of Geometric Brownian Motion Process and everything has been going fine, but know I have tried to do it with jumps. I have create a vector of jumps and then added this into my log-likelihood equation, know I am getting a message: NA in the initial gradient My codes is hear # n<-length(combinedlr) j<-c(1,2,3,4,5,6,7,8,9,10)