[R] Solving a simple linear equation using uniroot give error object 'x' not found

Sorkin, John j@ork|n @end|ng |rom @om@um@ry|@nd@edu
Tue Oct 6 17:00:59 CEST 2020


Colleagues,
I am trying to learn to use uniroot to solve a simple linear equation. I define the function, prove the function and a call to the function works. When I try to use uniroot to solve the equation I get an error message,
Error in yfu n(x,10,20) : object 'x' not found.

I hope someone can tell we how I can fix the problem

  if(!require(rootSolve)){install.packages("rootSolve")}
  library(rootSolve)

  # Define the function
  yfun <- function(x,diffMean,diffSE) ((abs(diffMean)-x)/diffSE)
  # Prove the function and a call to the function work
  yfun(10,100,10)
  # use uniroot to find a solution to the
  # function in the range -100 to 100
  uniroot(yfun(x,10,20),c(-100,100))


My output:
>   # Define the function
>   yfun <- function(x,diffMean,diffSE) ((abs(diffMean)-x)/diffSE)
>   # Prove the function and a call to the funciton works
>   yfun(10,100,10)
[1] 9
>   # use uniroot to find a solution to the
>   # funciton in the range -100 to 100
>   uniroot(yfun(x,10,20),c(-100,100))
Error in yfun(x, 10, 20) : object 'x' not found

Thank you,
John


John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)


	[[alternative HTML version deleted]]



More information about the R-help mailing list