A few issues
1) What does this function do? If you describe the problem and goal there might
be a better answer. We appreciate seeing that you have attempted a solution, but
you have trapped us all in blindly following your attempt.
2) This is an error checking phase of programming. Setting the seed is a good
idea. Just remember to unset the seed after finishing the debugging phase.
3) In uniroot you call the function, but the function expects an argument (zz)
that is not provided, and there is no default.
4) I set.seed(42), and entered ff(12) getting an answer of -0.1468287. Is this
the expected result?
Regards,
Tim
-----Original Message-----
From: R-help <r-help-bounces at r-project.org> On Behalf Of Md. Moyazzem
Hossain
Sent: Thursday, August 4, 2022 9:50 AM
To: J C Nash <profjcnash at gmail.com>
Cc: r-help mailing list <r-help at r-project.org>
Subject: Re: [R] Need help
[External Email]
Dear JN,
Thanks.
I do not check whether the function actually crosses zero or not. However, by
assumption, the value would be greater than zero.
Hossain
On Thu, Aug 4, 2022 at 2:40 PM J C Nash <profjcnash at gmail.com> wrote:
> Have you checked that your function actually crosses zero?
>
> You should also set a seed if you want a reproducible result.
>
> JN
>
> On 2022-08-04 09:30, Md. Moyazzem Hossain wrote:
> > Dear R Experts,
> >
> > I hope that you are doing well.
> >
> > I am facing a problem to find out the value of the following
> > function. I need help in this regard.
> >
> > #####
> > a=rnorm(1000, 110, 5)
> > b = rnorm(1000, -0.3, 0.4)
> > s = length(a)
> > lam=0.15
> > thr=70
> > r= 10
> >
> > ff = function(zz){
> > inner = vector("numeric", length = s)
> > for(k in 1:s){
> > inner[k]=(1- lam*((1+b[k]*((zz-thr)/a[k]))^(-1/b[k])))
> > }
> > answer = mean(inner)- (1- (1/r))
> > return(answer)
> > }
> > ########
> > out=uniroot(ff, lower = 0, upper = 10000 )$root out
> >
> > ########### Error ########
> > Error in uniroot(ff, lower = 0, upper = 10000) :
> > f.upper = f(upper) is NA
> >
> > Please help me. Thanks in advance.
> >
> > Take care.
> >
> > Hossain
> >
>
--
Best Regards,
Md. Moyazzem Hossain
Associate Professor
Department of Statistics
Jahangirnagar University
Savar, Dhaka-1342, Bangladesh
Website:
https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.juniv.edu%2Fteachers%2Fhossainmm&data=05%7C01%7Ctebert%40ufl.edu%7C5f71ee421f734ed8758b08da762083f7%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637952179362158744%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=z%2Bq179lF8MAawyc7KPXgNgGfwC9Sf0dnu34XRJxnpGY%3D&reserved=0
Research: *[image: Google Scholar]
<https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fscholar.google.com%2Fcitations%3Fhl%3Den%26user%3D-U03XCgAAAAJ&data=05%7C01%7Ctebert%40ufl.edu%7C5f71ee421f734ed8758b08da762083f7%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637952179362158744%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=N6t1WrH0iRPVvd4L%2FmwqJLNXzFaK1ViPo6v1PrD8gDk%3D&reserved=0>*
| *ResearchGate
<https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.researchgate.net%2Fprofile%2FMd_Hossain107&data=05%7C01%7Ctebert%40ufl.edu%7C5f71ee421f734ed8758b08da762083f7%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637952179362158744%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=qxDL1f3bKTdxyMYH8cQaxOwCmgclU1PUSB8iS1FdPRQ%3D&reserved=0>*
| *ORCID iD
<https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Forcid.org%2F0000-0003-3593-6936&data=05%7C01%7Ctebert%40ufl.edu%7C5f71ee421f734ed8758b08da762083f7%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637952179362158744%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=XEb%2BO2pnwNwDDOt0bDgRcIS6MzBd3q%2Bz8xnByUl6Y8w%3D&reserved=0>*
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C01%7Ctebert%40ufl.edu%7C5f71ee421f734ed8758b08da762083f7%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637952179362158744%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=g8ytuAGlQp5gAkXSiOkMzs0aurSim4hjX7MGg4dnjd4%3D&reserved=0
PLEASE do read the posting guide
https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=05%7C01%7Ctebert%40ufl.edu%7C5f71ee421f734ed8758b08da762083f7%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637952179362158744%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=GhE0lfrdqQ8fe4YXl3PwxtTAG2SPgG6BYzv5eUXe2UQ%3D&reserved=0
and provide commented, minimal, self-contained, reproducible code.