[R] Quicker way to apply values to a function

casperyc casperyc at hotmail.co.uk
Fri Mar 23 00:17:20 CET 2012


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 to do this other than loops?

For now, the 'output' vector v is not so informative. Is there a way to
'show' me for what combinations of mu and sigma, the resulting values 'v'
are from?

Thanks.



-----
###################################################
PhD candidate in Statistics
School of Mathematics, Statistics and Actuarial Science, University of Kent
###################################################

--
View this message in context: http://r.789695.n4.nabble.com/Quicker-way-to-apply-values-to-a-function-tp4497293p4497293.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list