search for: mfun

Displaying 18 results from an estimated 18 matches for "mfun".

Did you mean: mfn
2023 Dec 19
1
[External] Re: zapsmall(x) for scalar x
>>>>> Steve Martin >>>>> on Mon, 18 Dec 2023 07:56:46 -0500 writes: > Does mFUN() really need to be a function of x and the NA values of x? I > can't think of a case where it would be used on anything but the non-NA > values of x. > I think it would be easier to specify a different mFUN() (and document this > new argument) if the function has o...
2023 Dec 18
1
[External] Re: zapsmall(x) for scalar x
Does mFUN() really need to be a function of x and the NA values of x? I can't think of a case where it would be used on anything but the non-NA values of x. I think it would be easier to specify a different mFUN() (and document this new argument) if the function has one argument and is applied to the no...
2010 Feb 12
1
using mle2 for multinomial model optimization
...############################################## cohort<-c(50,54,50) #imaginary harvest numbers of a cohort harvested over 3 years l<-length(cohort)+1 #nr of cell probabilities h<-c(0.2,0.3,1) #harvest rates for the 3 diferent years S<-c(0.9,0.8) #survival rates mfun <- function(d) { S<-S #survival rate h<-h #harvest rate l<-length(d) p<-rep(0,l) #Cell probabilities p[1]<-h[1] prod<-(1-h[1])*S[1] for (i in 2:(l-1)){ p[i]<-prod*h[i] prod<-prod*(1-h[i])*S[i]...
2006 Jan 19
1
nls profiling with algorithm="port" may violate bounds (PR#8508)
...b<0) stop("bounds violated") a*x/(1+a*b*x) } m1 = nls(y~gfun(a,b,x),algorithm="port", lower=c(0,0),start=c(a=1,b=1)) try(confint(m1)) ---------------- for what it's worth, the logic appears to be OK in mle in the stats4 library: -------------- library(stats4) mfun <- function(a,b,s) { if (a<0 || b<0 || s<0) stop("bounds violated") -sum(dnorm(y,a*x/(1+a*b*x),sd=s,log=TRUE)) } m2 = mle(minuslogl=mfun, start=list(a=1,b=1,s=0.1), method="L-BFGS-B",lower=c(0.002,0.002,0.002)) confint(m2) m2b = mle(minuslogl=mfun,...
2012 Jun 19
1
Error when trying to update cpglm model
...,mu,phi) ## cpglm model modPC1<-cpglm(resp~period,data=dat) head(modPC1@model.frame) ## Simulating new response vector and re-fitting the model sim.hnp<-function(glmfit){   dat.1<-glmfit@model.frame   n<-nrow(dat.1)   dat.1[,1]<-rtweedie(n,glmfit$p,fitted(glmfit),glmfit$phi)      mfun<-update(object=glmfit,data=dat.1)   # rp<-resid(mfun,type='pearson')   # sort(abs(rp)) } sim.hnp(modPC1) # Error in is.data.frame(data) : object 'dat.1' not found [[alternative HTML version deleted]]
2005 Feb 25
2
display full form in args
Forgive me for I do not fully comprehend the idea of classes and methods but I was wondering if someone could help explain why the function args () behaves the way it does. Why does args(cut) show the simplified version instead of the more complete one as in help("cut"). This is true for few other functions (e.g. plot, rep). > args(cut) function (x, ...) Sometime I can get
2023 Dec 18
1
[External] Re: zapsmall(x) for scalar x
...use a 99% > percentile instead of the max(), or allowing to exclude +Inf > from the "mx"; but -- compared to your zapsmall2() -- > to allow reproducible automatic choice : > > > zapsmall <- function(x, digits = getOption("digits"), > mFUN = function(x, ina) max(abs(x[!ina])), > min.d = 0L) > { > if (length(digits) == 0L) > stop("invalid 'digits'") > if (all(ina <- is.na(x))) > return(x) > mx <- mFUN(x, ina) > round(x, digits = if(mx > 0)...
2010 Mar 24
0
optimize a joint lieklihood with mle2
...: ##1 I manage to write the joint lieklihood (it's very long which is why I don't put it here), but I don't know how to write the correct argument for the mle2 function. Here is what I've tried: ################################## the lieklihood function to be optimized is called mfun(logN, s, h=h, cohort=cohort). I want to maximize the vectors logN and s. I define the starting values for logN as svec1 and for s as svec2 then I write for the optimization: m1 = mle2(mfun,start=list(svec1=logN,svec2=s), method="L-BFGS-B",lower=lower,upper=10, vecpar=TRUE,...
2006 Jan 17
0
nls profile with port/constraints
...| b<0) stop("bounds violated") a*x/(1+a*b*x) } m1 = nls(y~gfun(a,b,x),algorithm="port", lower=c(0,0),start=c(a=1,b=1)) try(confint(m1)) ---------------- for what it's worth, the logic appears to be OK in mle in the stats4 library: -------------- library(stats4) mfun <- function(a,b,s) { if (a<0 || b<0 || s<0) stop("bounds violated") -sum(dnorm(y,a*x/(1+a*b*x),sd=s,log=TRUE)) } m2 = mle(minuslogl=mfun, start=list(a=1,b=1,s=0.1), method="L-BFGS-B",lower=c(0.002,0.002,0.002)) confint(m2) m2b = mle(minuslogl=mfun,...
2015 Mar 24
2
robust updating methods
...}) } else call Here is an adapted even-more-minimal version of your code, which seems to work with the version of update.merMod I just pushed to github, but fails for glm(): ## https://github.com/ThierryO/testlme4/blob/master/R/fit_model_ci.R fit_model_ci <- function(formula, dataset, mfun=glmer){ model <- mfun( formula = formula, data = dataset, family = "poisson" ) ci <- confint(model) return(list(model = model, confint = ci)) } library("lme4") set.seed(101) dd <- data.frame(f=factor(rep(1:10,each=100)),...
2009 Jan 19
1
further notes on model.frame issue
This is a follow-up on my note of Saturday. Let me start with two important clarifications - I think this would be a nice addition, but I've had exactly one use for it in the 15+ years of developing the survival package. - I have a work around for the current case. Prioritize accordingly. The ideal would be to change survexp as follows: fit <- survexp( ~ gender,
2015 Mar 27
0
robust updating methods
...pted even-more-minimal version of your code, which > seems to work with the version of update.merMod I just pushed to > github, but fails for glm(): > > > ## > https://github.com/ThierryO/testlme4/blob/master/R/fit_model_ci.R > fit_model_ci <- function(formula, dataset, mfun=glmer){ model <- > mfun( formula = formula, data = dataset, family = "poisson" ) ci <- > confint(model) return(list(model = model, confint = ci)) } > > library("lme4") set.seed(101) dd <- > data.frame(f=factor(rep(1:10,each=100)), y=rpois(2,1000)) >...
2011 Nov 26
2
simplify source code
Hi I would like to shorten mod1 <- nls(ColName2 ~ ColName1, data = table, ...) mod2 <- nls(ColName3 ~ ColName1, data = table, ...) mod3 <- nls(ColName4 ~ ColName1, data = table, ...) ... is there something like cols = c(ColName2,ColName3,ColName4,...) for i in ... mod[i-1] <- nls(ColName[i] ~ ColName1, data = table, ...) I am looking forward to help Christof
2023 Dec 18
1
[External] Re: zapsmall(x) for scalar x
...n more flexible, e.g. allowing to use a 99% percentile instead of the max(), or allowing to exclude +Inf from the "mx"; but -- compared to your zapsmall2() -- to allow reproducible automatic choice : zapsmall <- function(x, digits = getOption("digits"), mFUN = function(x, ina) max(abs(x[!ina])), min.d = 0L) { if (length(digits) == 0L) stop("invalid 'digits'") if (all(ina <- is.na(x))) return(x) mx <- mFUN(x, ina) round(x, digits = if(mx > 0) max(min.d, digits - as.numeric(log10(mx))) els...
2013 Jan 23
3
Pasting a list of parameters into a function
I need to repeat a function many times, with differing parameters held constant across iterations. To accomplish this, I would like to create a list (or vector) of parameters, and then insert that list into the function. For example: q<-("l,a,b,s") genericfunction<-function(q){ } ###### The equivalent code would of course be genericfunction<-function(l,a,b,s){ } Any help
2009 Feb 03
5
Large file size while persisting rpart model to disk
I am using rpart to build a model for later predictions. To save the prediction across restarts and share the data across nodes I have been using "save" to persist the result of rpart to a file and "load" it later. But the saved size was becoming unusually large (even with binary, compressed mode). The size was also proportional to the amount of data that was used to create the
2015 Mar 22
2
robust updating methods
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 WARNING: this is long. Sorry I couldn't find a way to compress it. Is there a reasonable way to design an update method so that it's robust to a variety of reasonable use cases of generating calls or data inside or outside a function? Is it even possible? Should I just tell users "don't do that"? * `update.default()` uses
2023 Dec 18
1
[External] Re: zapsmall(x) for scalar x
Le 17/12/2023 ? 18:26, Barry Rowlingson a ?crit?: > I think what's been missed is that zapsmall works relative to the absolute > largest value in the vector. Hence if there's only one > item in the vector, it is the largest, so its not zapped. The function's > raison d'etre isn't to replace absolutely small values, > but small values relative to the largest.