[R] Need help

Ebert,Timothy Aaron
Thu, 04 Aug 2022 14:27:56 -0000

I wish I could edit my earlier reply.
ff(144.43) returns 0.03142121, but ff(144.44) returns NaN.
ff(12) returns -0.1468287

out=uniroot(ff, lower=12, upper =144) does not have errors.
out is a list of 5.
$root is 112
$f.root is 1.09e-08
$iter is 5
$Init.it is NA
$estim.prec is 6.1e-05

Is this working?

Regards,
Tim

-----Original Message-----
From: R-help <r-help-bounces at r-project.org> On Behalf Of Ebert,Timothy
Aaron
Sent: Thursday, August 4, 2022 10:09 AM
To: Md. Moyazzem Hossain <hossainmm at juniv.edu>; 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]

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&amp;data=05%7C01%7Ctebert%40ufl.edu%7Ca36bab5860dc491744ea08da762360d7%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637952191569778102%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=Vh2lFXXqsLRyKwQES0mlh0LP%2FEtn%2FMfZ56Y9Q1vGRAw%3D&amp;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&amp;data=05%7C01%7Ctebert%40ufl.edu%7Ca36bab5860dc491744ea08da762360d7%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637952191569778102%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=st16paDG0HelgvvZZcIlstIEKmayjZFSNdujRJQtFsY%3D&amp;reserved=0>*
| *ResearchGate
<https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.researchgate.net%2Fprofile%2FMd_Hossain107&amp;data=05%7C01%7Ctebert%40ufl.edu%7Ca36bab5860dc491744ea08da762360d7%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637952191569778102%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=aB9z5UrHElxeTfUVTJB6L8Sj2enqLGWjBuEXXud%2BRyI%3D&amp;reserved=0>*
| *ORCID iD
<https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Forcid.org%2F0000-0003-3593-6936&amp;data=05%7C01%7Ctebert%40ufl.edu%7Ca36bab5860dc491744ea08da762360d7%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637952191569778102%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=OfjVBjaUn8LaViyL9auEJRxdyx7%2Fs7Du1UPauifNDPs%3D&amp;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&amp;data=05%7C01%7Ctebert%40ufl.edu%7Ca36bab5860dc491744ea08da762360d7%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637952191569778102%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=YUut6AHh2ON5dCwKO9c9T1rPvRD1rfQirZCEASNWOfg%3D&amp;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&amp;data=05%7C01%7Ctebert%40ufl.edu%7Ca36bab5860dc491744ea08da762360d7%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637952191569778102%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=MKsMalwzucmuzoHVv1BWSPE88zD9bQbsAoHLEESlwSo%3D&amp;reserved=0
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
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&amp;data=05%7C01%7Ctebert%40ufl.edu%7Ca36bab5860dc491744ea08da762360d7%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637952191569778102%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=YUut6AHh2ON5dCwKO9c9T1rPvRD1rfQirZCEASNWOfg%3D&amp;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&amp;data=05%7C01%7Ctebert%40ufl.edu%7Ca36bab5860dc491744ea08da762360d7%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637952191569778102%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=MKsMalwzucmuzoHVv1BWSPE88zD9bQbsAoHLEESlwSo%3D&amp;reserved=0
and provide commented, minimal, self-contained, reproducible code.