Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Optimize / solve equation for unknown exponent

I have dataframe with the following variables: a and b as predictors and c as outcome. My formula is:
c = (a^x) / (a^x + b^x)
How to solve for x?

Example data:

dat <- data.frame(a = runif(5, 1, 100), b = runif(5, 10, 20), c = runif(5, 0, 1))

Reply to comment:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What is your expected output? A single x-value from least squares fitting, or a column x?

The whole column (sum of all row errors). I want to minimize the error for every row.

>Solution :

You can use the following code

library(minpack.lm)

dataset = data.frame(a = runif(5, 1, 100), b = runif(5, 10, 20), c = runif(5, 0, 1)) 

fun <- as.formula(c ~ a^x/(a^x + b^x))

#Fitting model using minpack.lm package
nls.out1 <- nlsLM(fun, 
                  data = dataset,
                  start=list(x=1),
                  algorithm = "LM",
                  control = nls.lm.control(maxiter = 500))

summary(nls.out1)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading