Skip to content

translate formula into R code

2 messages · Jeff Newmiller, David L Carlson

#
Cc'd back to the list... always use reply-all.

You say res should have been LSS but LSS is a scalar so the for loop will only run once. What does a successful output look like for a sample input? How do you (we) know when success has been achieved?

In fact, what is the formula you want to implement?  If your code below is the definition of your "formula" then we are left with no destination. You either need to add a reference (paper citation?) or a set of inputs and corresponding outputs. 

Here are some resources that describe how to make a reproducible example [1][2][3]:

[1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

[2] http://adv-r.had.co.nz/Reproducibility.html

[3] https://cran.r-project.org/web/packages/reprex/index.html
#
The attached png file shows the expected output. The loop is complicated because the values multiplied shift in value and sign so your effort to sum the values along the way fails. It we compute the first two values directly and create arrays to handle the changing multipliers, the loop is pretty simple:
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] -200  150 -200  150 -200  150 -200  150 -200   150
[2,]  200 -250  200 -250  200 -250  200 -250  200  -250
[1] 150 200
+     r <- i %% 2 + 1
+     s <- seq_len(i-1)
+     L[i] <- abs(sum(L[s] * rows[r, s]))/ dnom[r]
+ }
[1] 0.10000000 0.13333333 0.06666667 0.08888889 0.11111111 0.14814815 0.18518519
 [8] 0.24691358 0.30864198 0.41152263

Matches the values in your png.


-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352

-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Jeff Newmiller
Sent: Tuesday, June 20, 2017 9:38 AM
To: Wolfgang K <mails00000 at gmail.com>
Cc: R-help <r-help at r-project.org>
Subject: Re: [R] translate formula into R code

Cc'd back to the list... always use reply-all.

You say res should have been LSS but LSS is a scalar so the for loop will only run once. What does a successful output look like for a sample input? How do you (we) know when success has been achieved?

In fact, what is the formula you want to implement?  If your code below is the definition of your "formula" then we are left with no destination. You either need to add a reference (paper citation?) or a set of inputs and corresponding outputs. 

Here are some resources that describe how to make a reproducible example [1][2][3]:

[1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

[2] http://adv-r.had.co.nz/Reproducibility.html

[3] https://cran.r-project.org/web/packages/reprex/index.html