Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7905551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:31:43+00:00 2026-06-03T10:31:43+00:00

not for the first time, I guess that the answer is quite simple. But

  • 0

not for the first time, I guess that the answer is quite simple. But searching for R solutions is regularly hard work and after two hours its probably at time to ask someone…

I am working with a non-linear formula (this is only the first work on it, it will actually become non-linear soon) and to test my initial values, i would like to simply calculate the values over a series of x values.

Here is some code:

x <- c(1,2,3,4,5,6,7,8,9,10,11,12) #etc
y <- c(NA,332,248,234,84,56,26,24,27,33,37,25) #etc
# This is my formula I shall soon expand
fEst <- y ~ 1 / (x / a + 1) * b
# Initial value
a <- 800
# Initial value based on inverted formula and second measure
b <- y[2] * (x[2] / a + 1)

# Can i use my formula fEst to do this step?
p <- 1 / (x / a + 1) * b

The point is that I am working on the formula – and it seems strange to make each change, twice…

What I found was a package nls2 where something like this was possible and a function apply.a.formula which seems to be an element from another package – but as this is a very basic use of a function, I guess that the R base packe already has the appropriate functions. Just … where?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T10:31:45+00:00Added an answer on June 3, 2026 at 10:31 am

    I came across this thread whilst looking up the avenues you’d tried and the solution posted by Gabor. Note that apply.a.formula() is a made up function name that the OP in the thread was looking to find a real function for.

    Using the example that Gabor provided in the thread this is a solution using the nls2 package:

    ## your data
    x <- c(1,2,3,4,5,6,7,8,9,10,11,12) #etc
    y <- c(NA,332,248,234,84,56,26,24,27,33,37,25) #etc
    # This is my formula I shall soon expand
    fEst <- y ~ 1 / (x / a + 1) * b
    # Initial value
    a <- 800
    # Initial value based on inverted formula and second measure
    b <- y[2] * (x[2] / a + 1)
    
    ## install.packages("nls2", depend = TRUE) if not installed
    require(nls2)
    fitted(nls2(fEst, start = c(a = a, b = b), alg = "brute"))
    

    The last line gives:

    R> fitted(nls2(fEst, start = c(a = a, b = b), alg = "brute"))
     [1] 332.4145 332.0000 331.5866 331.1741 330.7627 330.3524 329.9430 329.5347
     [9] 329.1273 328.7210 328.3157 327.9113
    attr(,"label")
    [1] "Fitted values"
    

    which is essentially the same as 1 / (x / a + 1) * b would give:

    R> 1 / (x / a + 1) * b
     [1] 332.4145 332.0000 331.5866 331.1741 330.7627 330.3524 329.9430 329.5347
     [9] 329.1273 328.7210 328.3157 327.9113
    

    From the comments, Carl Witthoft notes that if you want to generalise equations like 1 / (x / a + 1) * b then a function might be a useful way of encapsulating the operation without typing out 1 / (x / a + 1) * b every time. For example

    myeqn <- function(a, b, x) { 1 / (x / a + 1) * b }
    
    R> myeqn(a, b, x)
    [1] 332.4145 332.0000 331.5866 331.1741 330.7627 330.3524 329.9430 329.5347
    [9] 329.1273 328.7210 328.3157 327.9113
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently had my app certified (first time!) but not automatically published. The game
I've recently started using an IoC container for the first time, but I'm not
First of all I guess that fatal error: maximum execution time exceeded in PHP
It is not the first time i see it Ive seen in Facebook source
This is my first time working with file i/o in java, and it's not
As a developer using DB2 for the first time, I'm not familiar with what
this is my first time posting here, but I didn't know where else to
This is my first question that I haven't been able to find an answer
Ok, very simple question this time (though the answer seems elusive for I can't
I have a problem with selecting not first selector using attributeContains jQuery('div[id*=abc]:not(:first)').hide();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.