similar to: integrate

Displaying 20 results from an estimated 10000 matches similar to: "integrate"

2013 Apr 09
0
[R-SIG-Finance] EM algorithm with R manually implemented?
Moved to R-help because there's no obvious financial content. Michael On Sat, Apr 6, 2013 at 10:56 AM, Stat Tistician <statisticiangermany at gmail.com> wrote: > Hi, > I want to implement the EM algorithm manually, with my own loops and so. > Afterwards, I want to compare it to the normalmixEM output of mixtools > package. > > Since the notation is very advanced, I
2011 Feb 17
1
Integrate with an indicator function
Hi all, I have some some problem with regard to finding the integral of a function containing an indicator function. please see the code below: func1 <- function(x, mu){ (mu^2)*dnorm(x, mean = mu, sd = 1)*dgamma(x, shape=2)} m1star <- function(x){ integrate(func1, lower = 0, upper = Inf,x)$val} T <- function(x){ 0.3*dnorm(x)/(0.3*dnorm(x)+0.7*m1star(x))} func2 <-
2011 Feb 17
1
Integration with an Indicator Function in R
Hi all, I have some some problem with regard to finding the integral of a function containing an indicator function. please see the code below: func1 <- function(x, mu){ (mu^2)*dnorm(x, mean = mu, sd = 1)*dgamma(x, shape=2)} m1star <- function(x){ integrate(func1, lower = 0, upper = Inf,x)$val} T <- function(x){ 0.3*dnorm(x)/(0.3*dnorm(x)+0.7*m1star(x))} func2 <-
2012 Apr 18
0
Numerical integration again
Hi all, Here is an integration function require(pracma) # for 'quadinf' myint=function(j) { quadinf(function(x) (1/(1+exp(-x)))^j*(1-1/(1+exp(-x)))^(k-j)*dnorm(x,mu,casigma),-Inf,Inf) } in any optimization routine. It works fine most of the time but failed with some particular sets of values, say one of the following: k=20 mu=-1.978295 casigma=0.008326927 >
2004 Mar 02
2
Problem with Integrate
The background: I'm trying to fit a Poisson-lognormal distrbutuion to some data. This is a way of modelling species abundances: N ~ Pois(lam) log(lam) ~ N(mu, sigma2) The number of individuals are Poisson distributed with an abundance drawn from a log-normal distrbution. To fit this to data, I need to integrate out lam. In principle, I can do it this way: PLN1 <- function(lam, Count,
2012 Mar 22
2
Quicker way to apply values to a function
Hi all, myint=function(mu,sigma){ integrate(function(x) dnorm(x,mu,sigma)/(1+exp(-x)),-Inf,Inf)$value } mymu=seq(-3,3,length(1000)) mysigma=seq(0,1,length(500))[-1] k=1 v=c() for (j in 1:length(mymu)) { for (i in 1:length(mysigma)) { v[k]=myint(mymu[j],mysigma[i]) k=k+1 } } Basically, I want to investigate for what values of mu and sigma, the integral is divergent. Is there another way
2006 May 05
0
Spline integration & Gaussian quadrature (was: gauss.quad.prob)
Spencer Thanks for your thoughts on this. I did a bit of work and did end up with a method (more a trick), but it did work. I am certain there are better ways to do this, but here is how I resolved the issue. The integral I need to evaluate is \begin{equation} \frac{\int_c^{\infty} p(x|\theta)f(\theta)d\theta} {\int_{-\infty}^{\infty} p(x|\theta)f(\theta)d\theta} \end{equation} Where
2003 Dec 23
7
Sweave question
Using Sweave in the tools library (R version 1.8.0: sorry i havent upgraded), it seems i cant use if statements in R chunks that make graphs. i have this: <<fig=TRUE,echo=F>>= par(mfrow=c(1,1)) if(exists("x")) plot(x,x) else{ plot(1,1,type="n") text(1,1,"data not available.\n") } @ and I get this error: Error: chunk 6 Error in parse(file, n,
2011 Nov 14
2
how to include integrate in a function that can be solved with uniroot?
Hallo, I am trying to define expectation as an integral and use uniroot to find the distribution parameter for a given expectation. However I fail to understand how to define properly the functions involved and pass the parameters correctly. Can anyone help me out? Thanks, Gerrit Draisma. This what I tried: ======= > # exponential density > g <- function(x,lambda){ lambda
2009 Dec 04
1
z to r transformation within print.rma.uni and forest from the package metafor
Dear R community, I'm using the ,metafor'-package by Wolfgang Viechtbauer (Version: 0.5-5) to calculate random-effects meta-analyses using Correlations and Sample Sizes as the raw data. (By the way: Really a nice piece of work, Wolfgang! Thanks heaps.) I specified the "rma.uni' function so that it looks like this: MAergebnis<-rma.uni(ri=PosOutc, ni=N,
2005 Oct 07
1
Error in integrate
I'm using R 2.0.1 under Windows XP. I get the following message when I run the code listed below. I don't seem to have any problems using the function "slice" outside "integrate". Error in integrate(slice, 0, Inf, , , , , , , a, b) * delta : non-numeric argument to binary operator [ By the way, I'm trying to evaluate a two-dimensional integral by
2003 Feb 06
1
rdbi segmentation fault (fwd)
one more bit of information about this problem. If I start R as the user "postgres" i dont have the segmentation fault. ---------- Forwarded message ---------- Date: Wed, 5 Feb 2003 19:19:39 -0500 (EST) From: Rafael A. Irizarry <ririzarr at jhsph.edu> Reply-To: rafa at jhu.edu To: "R-Help (E-mail)" <r-help at r-project.org> Subject: rdbi segmentation fault hi! i
2011 Feb 26
0
A problem about realized garch model
Hi, I am trying to write the Realized GARCH model with order (1,1) The model can be describe bellow: r_t = sqrt( h_t) * z_t logh_t = w + b*logh_(t-1) + r*logx_(t-1) logx_t = c + q*logh_t + t1*z_t +t2*(z_t ^2 -1) + u_t and z follow N(0,1) , u follow N(0, sigma.u^2) But I'm troubled with the simulation check for my code. After I simulate data from the model and estimate the data, I
2012 Sep 25
1
how to pass a function to a function inside a function
Hi, I'm trying to compile two functions into one function. the first funtion is called 'fs' which is self-made function, another function is from the built-in 'integration' function that is copy-paste-edited. If built separatey, these functions work well. However that is not the case if combines together, where certainly I made mistake somewhere when constructing the code.
2012 Jul 03
1
integral with error:non-finite function value
Hi guys, I'm trying to use the the integral function to estimate the area under a PDF and a crossing curve. first I stated the function with several vectors in it: fn=function(a,b,F,mu,alpha,xi) { x<-vector() fs<-function(x) { c <- (mu+(alpha*(1-(1-F)^xi)/xi)) tmp <- (1 + (xi * (x - mu))/alpha) ((as.numeric(tmp > 0) * (tmp^(-1/xi - 1) *
2004 Jul 02
2
hclust
im using plclust and want the labels to be different colors. i took a look at getS3method("plot","hclust") and saw a call to .Internal. i looked at the help on .Internal and dont know where to go next. any help appreciated! thanks, rafael
2007 Sep 12
0
Problem with integrate()
Hello! I have a problem with integrate() in my function nctspa(). Integrate produces an error message "evaluation of function gave a result of wrong length". I don't know what that means. Could anyone suggest me what is wrong with my function? These are the examples of function calls that work OK: nctspa(a=1:10,n=5) nctspa(a=1:10, n=5, mu=2, theta=3, renorm=0) This does not work:
2012 Jul 11
2
nls problem: singular gradient
Why fails nls with "singular gradient" here? I post a minimal example on the bottom and would be very happy if someone could help me. Kind regards, ########### # define some constants smallc <- 0.0001 t <- seq(0,1,0.001) t0 <- 0.5 tau1 <- 0.02 # generate yy(t) yy <- 1/2 * ( 1- tanh((t - t0)/smallc) * exp(-t / tau1) ) + rnorm(length(t))*0.01 # show the curve
2005 Aug 04
1
Where the error message comes from?
Hi all: I get the following error message that I am not able to resolve. Error in if (const(t, min(1e-08, mean(t)/1e+06))) { : missing value where TRUE/FALSE needed It appears right before the last data.frame statement. Below is the program that simulates data from one way random effects model and then computes normality and bootstrap confidence interval for
2012 Aug 01
1
optim() for ordered logit model with parallel regression assumption
Dear R listers, I am learning the MLE utility optim() in R to program ordered logit models just as an exercise. See below I have three independent variables, x1, x2, and x3. Y is coded as ordinal from 1 to 4. Y is not yet a factor variable here. The ordered logit model satisfies the parallel regression assumption. The following codes can run through, but results were totally different from what I