similar to: how to see what's wrong with a self written function?

Displaying 20 results from an estimated 3000 matches similar to: "how to see what's wrong with a self written function?"

2010 Aug 25
4
Secant Method Convergence (Method to replicate Excel XIRR/IRR)
Hi, I am new to R, and as a first exercise, I decided to try to implement an XIRR function using the secant method. I did a quick search and saw another posting that used the Bisection method but wanted to see if it was possible using the secant method. I would input a Cash Flow and Date vector as well as an initial guess. I hardcoded today's initial date so I could do checks in Excel.
2012 Nov 08
3
vectorized uni-root?
dear R experts--- I have (many) unidimensional root problems. think loc.of.root <- uniroot( f= function(x,a) log( exp(a) + a) + a, c(.,9e10), a=rnorm(1) ) $root (for some coefficients a, there won't be a solution; for others, it may exceed the domain. implied volatilities in various Black-Scholes formulas and variant formulas are like this, too.) except I don't need 1 root, but a
2010 Nov 12
1
what's wrong with this 'length' in function?
Hi all, I am having a trouble with this function I wrote ################################################### p26=function(x,alpha){ # dummy variable j=1 ci=matrix(ncol=2,nrow=3) while (j<4){ if (j==2) {x=x+c(-1,1)*0.5} ci[j,]= x+qnorm(1-alpha/2)^2/2+ c(-1,1)*qnorm(1-alpha/2)* sqrt(x+qnorm(1-alpha/2)^2/4) j=j+1 if (j==3) { # exact x=x-c(-1,1)*0.5
2012 May 16
3
triangular matrices input/output
Hi, Is there any package that deals with triangular matrices? Say ways of inputting an upper (lower) triangular matrix? Or convert a vector of length 6 to an upper (lower) triangular matrix (by row/column)? Thanks! ----- ###################### PhD candidate in Statistics Big R Fan Big LEGO Fan Big sTaTs Fan ###################### -- View this message in context:
2011 Sep 11
2
how to quote "factors" in a function?
### code ### x=sample(LETTERS[1:26],100,T) prob=function(y){ count=sum(x==y) total=length(x) count/total } ### end ### How do I quote the letters A,B,C,D ect, in order to make the "prob" function return the weights of the desired Letter? Thanks! -- View this message in context:
2010 Dec 18
3
use of 'apply' for 'hist'
Hi all, ########################################## dof=c(1,2,4,8,16,32) Q5=matrix(rt(100,dof),100,6,T,dimnames=list(NULL,dof)) par(mfrow=c(2,6)) apply(Q5,2,hist) myf=function(x){ qqnorm(x);qqline(x) } apply(Q5,2,myf) ########################################## These looks ok. However, I would like to achieve more. Apart from using a loop, is there are fast way to 'add' the titles to be
2013 Apr 01
2
Is DUD available in nls()?
SAS has DUD (Does not Use Derivatives)/Secant Method for nonlinear regression, does R offer this option for nonlinear regression? I have read the helpfile for nls() and could not find such option, any suggestion? Thanks, Derek [[alternative HTML version deleted]]
2011 Sep 22
1
nlm's Hessian update method
Hi R-help! I'm trying to understand how R's nlm function updates its estimate of the Hessian matrix. The Dennis/Schnabel book cited in the references presents a number of different ways to do this, and seems to conclude that the positive-definite secant method (BFGS) works best in practice (p201). However, when I run my code through the optim function with the method as "BFGS",
2010 Nov 08
3
how do i plot this "hist"?
Hi all, I have the following data in abc.dat ======================= 50 0 1 0 0 55 1 14 0 1 60 7 86 0 3 65 22 324 2 3 70 58 1035 1 7 75 30 2568 0 34 80 9 2936 15 162 85 27 2169 46 365 90 80 1439 212 432 95 236 1670 521 281 100 332 827 709 172 105 156 311 556
2010 Mar 07
3
barplot with factors problem
http://www.harding.edu/fmccown/R/#autosdatafile http://www.harding.edu/fmccown/R/#autosdatafile I am tring to get a barchat by factors, following the example in that link above. =========================== x=c(145,40,40,120,180, 140,155,90,160,95, 195,150,205,110,160, 45,40,195,65,145, 195,230,115,235,225, 120,55,50,80,45 ) y2=c( rep(as.character(1),5), rep(as.character(2),5),
2010 Nov 28
4
how to divide each column in a matrix by its colSums?
Hi, I have a matrix, say m=matrix(c( 983,679,134, 383,416,84, 2892,2625,570 ),nrow=3 ) i can find its row/col sum by rowSums(m) colSums(m) How do I divide each row/column by its rowSum/colSums and still return in the matrix form? (i.e. the new rowSums/colSums =1) Thanks. Casper -- View this message in context:
2010 Nov 20
3
how to add frequencies to barplot
Hi, I have count data x2=rep(c(0:3),c(13,80,60,27)) x2 0 1 2 3 13 80 60 27 I want to graph to be ploted as barplot(table(x2),density=4) how do I add relative frequency to it, like in hist(x2,labels=T) above the 'bar's Thanks. casper -- View this message in context: http://r.789695.n4.nabble.com/how-to-add-frequencies-to-barplot-tp3051923p3051923.html Sent from the R help
2010 Mar 26
2
R loop help
Hi, I am tring to write a loop to compute this, ========================== x1=c( rep(-1,4), rep(1,4) ) x2=c( rep(c(-1,-1,1,1),2) ) x3=c( rep(c(-1,1),4) ) x1*x2 x1*x3 x2*x3 ======================== suppose i have x1,x2,x3 i want to compute their ' two factor interactions', x1x2,x1x3 and x2x3, I wrote ======================== for(i in 1:2){ for( j in i+1:3){ xij=c()
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
2012 Mar 10
3
function input as variable name (deparse/quote/paste) ??
Hi all Say I have a function: myname=function(dat,x=5,y=6){ res<<-x+y-dat } for various input such as myname(dat1) myname(dat2) myname(dat3) myname(dat4) myname(dat5) how should I modify the 'res' line, to have new informative variable name correspondingly, such as dat1.res dat2.res dat3.res dat4.res dat5.res stored in the workspace. This is only an example of a complex
2010 Apr 13
3
writing function ( 'plot' and 'if') problem
=========================== myf=function(ds=1){ x=rnorm(10) y=rnorm(10) { #start of if if (ds==1) { list(x,y) } else (ds==2) { plot(x,y) } } # end of if } # end of function =========================== Hi All, the problem i am having here is, that I want to be able to control the display, lf ds=1, i want to just have a list, but it seem to always plot... Thanks. casper -- View this
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
2009 Dec 07
5
confint for glm (general linear model)
Hi, I have a glm gives summary as follows, Estimate Std. Error z value Pr(>|z|) (Intercept) -2.03693352 1.449574526 -1.405194 0.159963578 A 0.01093048 0.006446256 1.695633 0.089955471 N 0.41060119 0.224860819 1.826024 0.067846690 S -0.20651005 0.067698863 -3.050421 0.002285206 then I use confint(k.glm)
2013 Mar 31
1
DUD (Does not Use Derivatives) for nonlinear regression in R?
Hi, All SAS has DUD (Does not Use Derivatives)/Secant Method for nonlinear regression, does R offer this option for nonlinear regression? I have read the helpfile for nls() and could not find such option, any suggestion? Thanks, Derek [[alternative HTML version deleted]]
2012 Mar 23
3
R numerical integration
Hi all, Is there any other packages to do numerical integration other than the default 'integrate'? Basically, I am integrating: integrate(function(x) dnorm(x,mu,sigma)/(1+exp(-x)),-Inf,Inf)$value The integration is ok provided sigma is >0. However, when mu=-1.645074 and sigma=17535.26 It stopped working. On the other hand, Maple gives me a value of 0.5005299403. It is an