4

I would like to know how to proceed with the following non linear regression analysis, which is a simplified version of my real problem.

5 Participants where asked to observe the speed of three different cars: Audis, VWs and Porsches over a ten second time frame. This gives me the following data set:

S_t_c <- read.table(text = "
 time     S_c_1  S_c_2     S_c_3 
     1      20    15         40 
     2      45    30         50 
     3      60    45         60 
     4      75    60         60 
     5      90    70         60 
     6     105    70         90 
     7     120    70        120 
     8     125    70        140 
     9     130    70        160 
    10     145    70        180 
           ",header = T)

After observing the last 10 seconds, the 5 participants where then asked to guess how fast the car would go in t=11. This gives me this data:

S_11_i_c <-read.table(text = "
             i     c_1    c_2       c_3 
             1     150    70        190 
             2     155    70        200 
             3     150    75        195 
             4     160    80        190 
             5     150    75        180 
               ",header = T)

I now want to execute a non linear regression to estimate the free parameters of the following model:

The indices stand for the following:

i= participant
c=car brand
s=time

My problems are the sums as well as the fact that I have to estimate the parameters based on three different observations sets (for each car one). So I do not know how to code sums into a regression and I have problems with the facts that my DVs are dependent on different time-series IVs. I would like to learn how to do this in R.

EDIT: Attempt at solving the problem.

What I managed to do so far is write w_s and Sum_S:

function (x) {
    x = 0
    for (j in 0:9) {
    x <- x+ x^j
    }
}


w_s = beta_2^s / function(beta_2)

Sum_S_t_c <- data.frame(
    s = seq(1:9),
    c_1 = rnorm(9)  
    c_2 = rnorm(9)
    c_3 = rnorm(9)

)

Sum_S_t_c = 0
for (c in 2:4) {
    for (s in 0:9) {  
    Sum_S_t_c[s,c] <- Sum_S_t_c + S_t_c[10-s, c] 
    Sum_S_t_c = Sum_S_t_c[s,c]
    }
}

Now, I somehow need to fit these variables into a non-linear regression. This would be my dummy code for it:

For (c in 2:4) {
    for (i in 1:5) {
        for (s in 0:9) {    

        S_11_i_c ~ beta_0 +  beta_1 * Sum_S_t_c[s,c] * beta_2^s / function(beta_2)

        }
    }
}

I also need to set an upper and lower limit for beta_2, which I do not know how to do. I also wonder, if it even possible to use a function within a regression?

Edit:

Should I possibly group the DV and IVS somehow? If so, is it possible to group variables of two different data tables together?

Jj Blevins
  • 355
  • 1
  • 13
  • so you already have x_i,t? I don't really understand why it is a problem to sum over the two columns? – Ben Jun 29 '19 at 15:56
  • @Ben yes, I have `x_i,t` but I do not know how to code this problem properly with a non linear regression command. All examples I can find do regressions like `y ~ a/x + x*a^2` and none show how to apply something like `y_i ~ a/x_i + x_i*a^2` – Jj Blevins Jun 29 '19 at 16:40
  • isn't that basically the same? – Ben Jul 01 '19 at 06:47
  • @Ben why would it be the same? The coding is different – Jj Blevins Jul 01 '19 at 08:18
  • I don't get the notation: y ~ a/x is for me (almost) the same coding like y_i ~ a_i / x_i. At least, when I consider i as a row, representing the i-th data point. – Ben Jul 01 '19 at 13:34
  • @Ben Now, I understand. i is for column not row. I think I explained it clearly in my example? Do you think I should make it somehow clearer? – Jj Blevins Jul 01 '19 at 14:07
  • means, t is your row? If so, it doesn't change so much :) – Ben Jul 02 '19 at 06:15
  • How familiar are you with R? I'm not sure if I can't see the problem because I'm used to it or if I don't understand it.. – Ben Jul 02 '19 at 06:16
  • @Ben Could you provide an answer then? – Jj Blevins Jul 02 '19 at 09:08
  • When I'm free I will provide something how it looks in my eyes :) – Ben Jul 02 '19 at 09:23
  • @ben I completely changed the text of my question to make the problem more understandable. – Jj Blevins Jul 02 '19 at 09:43
  • @parfait I would love to try to solve this by myself and I looked for similar problems but to no success. Probably, I do not use the correct search terms for problems such as these but all I could fin is how to solve regressions where there is a set of DVs that are all related to the same IVs. You do not have to solve this problem for me, but I would love a nudge in the right direction. Maybe a link to a similar problem or a suggestions which function to use. I can post some made up code and pretend that it was my attempt at a solution, but truth be told, I do not know where to start here. – Jj Blevins Jul 02 '19 at 16:49
  • @Ben any free time to help me out here? – Jj Blevins Jul 04 '19 at 10:39
  • just wanted to do now but.. can you please arrange the data more accessible? Such that someone can use it directly without deleting all the spaces and so on? – Ben Jul 04 '19 at 19:13
  • Ah, you already came up with some coding. At first, what you are looking for, in case your model is a non-linear model, you might want to use nlm() -> https://stackoverflow.com/questions/40620277/r-how-can-the-nlm-function-be-used-for-optimization-with-multiple-variables – Ben Jul 04 '19 at 19:19
  • When using the proper syntax you will need much less code lines. – Ben Jul 04 '19 at 19:21
  • @Ben I added the data directly from R. Hope it is know easier to copy. – Jj Blevins Jul 04 '19 at 22:28
  • 1
    You're missing a closing `)` in `Sum_S = c(seq(0,3)`. It's also unwise to use `c` as a variable name, since that's the name of a function you're also using – camille Jul 07 '19 at 15:37

0 Answers0