search for: myfun2

Displaying 16 results from an estimated 16 matches for "myfun2".

Did you mean: myfun
2011 Jul 23
1
call a function with explicitly not setting an argument
Is there a way to call a function, and explicitly set an argument to 'not specified'? My situation is the following. I have a function which passes on most of its arguments to another function. The second function, myfun2, serializes all arguments and is out of my control. myfun <- function(...){ return(myfun2(...)); } now, the value for arguments of myfun are stored in variables. Say I want to call it with arguments 'foo' and 'bar', which are stored in variables 'myfoo' and 'myba...
2017 Jun 18
3
R_using non linear regression with constraints
...="red" ) + geom_point( x=objdtassmin$a , y=objdtassmin$b , colour="green" ) + scale_fill_continuous( name="SumSq", breaks = brks ) # Green point is brute-force solution # Red point is optimizer solution for myfun ############## myfun2 <- function( a, log1ab, r, t ) { ab <- 1000 - exp( log1ab ) ab * ( 1 - exp( -ab/a * r * t ) ) } objdta$log1ab <- with( objdta, log( 1000 - a * b ) ) objdta$myfun2 <- with( objdta , myfun2( a = a , log1ab = log1ab...
2017 Jun 18
0
R_using non linear regression with constraints
...constraint which is a*b<1000. At the moment your coefficients do satisfy that constraint so that dataset is not suitable for testing. A slight modification of the objective function to include the logical constraint as an additional factor does not "break" that particular solution.: myfun2=function(a,b,r,t){ prd=a*b*(1-exp(-b*r*t))*(a*b<1000) return(prd)} myfit=nlsLM(y~myfun2(a,b,r=2,t=x),data=mydata,start=list(a=2000,b=0.05), lower = c(1000,0), upper = c(3000,1)) #------------------ myfit Nonlinear regression model model: y ~ myfun2(a, b, r = 2, t = x)...
2017 Jun 18
3
R_using non linear regression with constraints
...is a*b<1000. > > At the moment your coefficients do satisfy that constraint so that dataset is not suitable for testing. A slight modification of the objective function to include the logical constraint as an additional factor does not "break" that particular solution.: > > myfun2=function(a,b,r,t){ > prd=a*b*(1-exp(-b*r*t))*(a*b<1000) > return(prd)} > > > myfit=nlsLM(y~myfun2(a,b,r=2,t=x),data=mydata,start=list(a=2000,b=0.05), > lower = c(1000,0), upper = c(3000,1)) > > #------------------ > myfit > Nonlinear regression m...
2017 Jun 18
2
R_using non linear regression with constraints
I am using nlsLM {minpack.lm} to find the values of parameters a and b of function myfun which give the best fit for the data set, mydata. mydata=data.frame(x=c(0,5,9,13,17,20),y = c(0,11,20,29,38,45)) myfun=function(a,b,r,t){ prd=a*b*(1-exp(-b*r*t)) return(prd)} and using nlsLM myfit=nlsLM(y~myfun(a,b,r=2,t=x),data=mydata,start=list(a=2000,b=0.05), lower = c(1000,0),
2017 Jun 18
0
R_using non linear regression with constraints
...>> >> At the moment your coefficients do satisfy that constraint so that dataset is not suitable for testing. A slight modification of the objective function to include the logical constraint as an additional factor does not "break" that particular solution.: >> >> myfun2=function(a,b,r,t){ >> prd=a*b*(1-exp(-b*r*t))*(a*b<1000) >> return(prd)} >> >> >> myfit=nlsLM(y~myfun2(a,b,r=2,t=x),data=mydata,start=list(a=2000,b=0.05), >> lower = c(1000,0), upper = c(3000,1)) >> >> #------------------ &gt...
2017 Jun 18
0
R_using non linear regression with constraints
...assmin$a > , y=objdtassmin$b > , colour="green" ) + > scale_fill_continuous( name="SumSq", breaks = brks ) > # Green point is brute-force solution > # Red point is optimizer solution for myfun > > ############## > > myfun2 <- function( a, log1ab, r, t ) { > ab <- 1000 - exp( log1ab ) > ab * ( 1 - exp( -ab/a * r * t ) ) > } > > objdta$log1ab <- with( objdta, log( 1000 - a * b ) ) > objdta$myfun2 <- with( objdta > , myfun2( a = a >...
2006 Jul 06
2
use of apply in a data frame on a row by row basis
...output of the function a bit more complex, it does not work : In this case I'm using a timeSeries object (from Rmetrics) library(fMultivar) timerange = timeSequence(from = "2001-04-11", length.out = 3,by = "weeks", format = "%Y-%m-%d", FinCenter = "GMT") myfun2 = function(x) timeSeries(rnorm(3),timerange) In this case, myfun2(df) returns only the result of the 1st row! BUT apply(df,1,myfun2) in this case, does work But I haven't used the "$" notation to access one field Now if I try (and that is the cas that bugs me currently) : myfun3 =...
2012 Jul 02
2
Constructing a list using a function...
Hi All I have a dataframe: myframe<-data.frame(ID=c("first","second"),x=c(1,2),y=c(3,4)) And I have a function myfun: myfun<-function(x,y) x+y I would like to write a function myfun2 that takes myframe and myfun as parameters and returns a list as below: mylist $first [1] 4 $second [2] 6 Could you please help me with this? Doesn't seem like the "apply" family of functions were intended for this case.
2011 Sep 03
2
problem in applying function in data subset (with a level) - using plyr or other alternative are also welcome
...unction myfun <- function(x) { x<- as.vector(x) ot1 <- ifelse(mydf[x[1]] == mydf[x[3]], 1, -1) ot2 <- ifelse(mydf[x[2]] == mydf[x[4]], 1, -1) qt <- ot1 + ot2 return(qt) } qt <- apply(mmat, 1, myfun) ydv <- c((y - mean(y))^2) qtd <- data.frame(ped, ydv, qt) # second function myfun2 <- function(dataframe) { vydv <- sum(ydv)*0.25 sumD <- sum(ydv * qt) Rt <- vydv / sumD return(Rt) } # using plyr require(plyr) dfsumd1 <- ddply(mydf,.(mydf$ped),myfun2) Here are 2 issues: (1) The output just one, I need the output for all three set of variables (as listed above) (...
2008 Jan 22
2
R object as a function
I want to use a function as an argument to ingtegrate it twice. See the following (senseless) example of a double integration: test<-function(sf,lo,up,rest) { innerFkn<-function(sf,lo) { inte=integrate(f=sf,lower=lo,upper=4) return( inte$value ) } integral=integrate(f=innerFkn,lower=1,upper=2,sf=sf,lo=lo,up=up) return( integral$vlaue+rest ) }
2004 Mar 11
1
how to pass extra parameters using call() or similar mechanism ?
I am trying to write a function, which would allow to call various methods and would pass to them extra arbitrary parameters. My first attempt was to use call() as illustrated below, but apparently '...' cannot be used in such context. How can this be achieved ? Best regards, Ryszard > myfun <- function(method, x, ...) { + v <- eval(call(method, x, ...)) + } > method =
2011 Jul 25
1
do.call in "with" construction
Dear all, I'd appreciate any help to rectify what must be a misconception of mine how environments work: ########################## myEnv <- new.env() myEnv$a.env <- 1 myEnv$symbols.env <- "a.env" a.global <- 2 symbols.global <- "a.global" myFun <- function(symbols){do.call("print", lapply(symbols, FUN=as.name))} do.call("myFun",
2005 Jun 07
9
how to define functions in such a situation
hi R folks, I need read a file from hardisk or www web. Then I need to define some new functions according to the contents of the read file. For example, i need write a package name "mypackage" like this: >library(mypackage) >read(some_file_on_web) #to see its content, suppose it contains: eat.drink.sleep then 3 new functions need to be created and usable. the problem is, how
2011 Jul 05
1
Create factor variable by groups
Hi, suppose that I have the following data.frame: cnae4 cnpj 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 Y 24996 10020470 1 1 2 12 16 21 17 51 43 19 183 24996 10020470 69 91 79 92 91 77 90 96 98 108 891 36145 10020470 0 0 0 0 2 83 112 97 91 144 529 44444 10023333 5 20 60 0 0 0 0 5 20 1000 1110 I would like to create a new variable X that indicates which
2010 Apr 15
4
Does "sink" stand for anything?
Hello Everyone,   Learning about R and its wonderful array of functions. If it's not obvious, I usually try to find out what a function stands for. I think this helps me remember better.   One function that has me stumped is "sink." Can anyone tell me if this stands for something?   Thanks,   Paul         __________________________________________________ [[alternative HTML