ElMaestro
★★★

Denmark,
2024-03-24 18:07
(262 d 18:25 ago)

(edited on 2024-03-24 18:24)
Posting: # 23918
Views: 6,238
 

 The order function [🇷 for BE/BA]

Hi all,

I am experiencing something that makes me question my sanity.

Consider this code
L=c(0.000000,  5161.096198,  18218.849691,   24977.065020,  108495.506990, 
    114018.413824,  459809.038038, 8691576.342850, 9917785.333365, 6694756.609860)
str(L) 
order(L) 
data.frame(L, order(L))


I get this result:

             L order.L.
1        0.000        1
2     5161.096        2
3    18218.850        3
4    24977.065        4
5   108495.507        5
6   114018.414        6
7   459809.038        7
8  8691576.343       10
9  9917785.333        8
10 6694756.610        9


I could indeed be wrong but the order does not look right, does it? The 10'th element should be 8'th.

Tried method="radix", method="shell", but it persists. A decreasing order, same thing.
I wonder if R thinks I am ordering characters or factors in spite of the str(L) output, but even if I do ordering on
as.numeric(as.character(L))
the problem persists.
Switched to my laptop which runs Windows 11 but I get the same output.
Did I mess up something in the global environment?
What am I overlooking here?

If I call sort(L) the sort looks fine.

Many thanks for any input.
:-)

Pass or fail!
ElMaestro
ElMaestro
★★★

Denmark,
2024-03-24 21:31
(262 d 15:01 ago)

@ ElMaestro
Posting: # 23919
Views: 5,688
 

 The order function

Hey

interesting.
Man, I never looked at the rank function until now. But it seems to be the important distinction between rank and order that answers my question.
:-)

Pass or fail!
ElMaestro
Helmut
★★★
avatar
Homepage
Vienna, Austria,
2024-03-24 22:12
(262 d 14:20 ago)

@ ElMaestro
Posting: # 23920
Views: 5,689
 

 The order function

Hi ElMaestro,

❝ Man, I never looked at the rank function until now. But it seems to be the important distinction between rank and order that answers my question.


Yep. Don’t know what you want to achieve, but:

L            <- c(0.000000, 5161.096198, 18218.849691, 24977.065020,
                  108495.506990, 114018.413824,  459809.038038, 8691576.342850,
                  9917785.333365, 6694756.609860)
df           <- data.frame(L = L, rk = rank(L))
names(df)[2] <- "rank(L)" # cosmetics

print(df)
             L rank(L)
1        0.000       1
2     5161.096       2
3    18218.850       3
4    24977.065       4
5   108495.507       5
6   114018.414       6
7   459809.038       7
8  8691576.343       9
9  9917785.333      10
10 6694756.610       8


print(df[with(df, order(L)), ])
             L rank(L)
1        0.000       1
2     5161.096       2
3    18218.850       3
4    24977.065       4
5   108495.507       5
6   114018.414       6
7   459809.038       7
10 6694756.610       8
8  8691576.343       9
9  9917785.333      10


print(df[with(df, order(rank(L))), ]) # same
             L rank(L)
1        0.000       1
2     5161.096       2
3    18218.850       3
4    24977.065       4
5   108495.507       5
6   114018.414       6
7   459809.038       7
10 6694756.610       8
8  8691576.343       9
9  9917785.333      10


If you simply want to order the L vector, use:

L <- L[order(L)]


Dif-tor heh smusma 🖖🏼 Довге життя Україна! [image]
Helmut Schütz
[image]

The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes
d_labes
★★★

Berlin, Germany,
2024-03-26 20:58
(260 d 15:34 ago)

@ ElMaestro
Posting: # 23925
Views: 5,577
 

 The order function

Dear öberster größter Meister

❝ Man, I never looked at the rank function until now. But it seems to be the important distinction between rank and order that answers my question.


Can you please elaborate: What is the important distinction between rank and order you detected?
I didn't got it.

Regards,

Detlew
ElMaestro
★★★

Denmark,
2024-03-27 09:43
(260 d 02:49 ago)

@ d_labes
Posting: # 23927
Views: 5,631
 

 The order function

Hi dlabes,

❝ Can you please elaborate: What is the important distinction between rank and order you detected?

❝ I didn't got it.



x=c(6,7,5,8)
rank(x)
order(x)


The rank output is:
2,3,1,4

Which means: #3 comes first (rank=1), then #2, then #1, then #4


The order output is:
3,1,2,4

Which means: When sorted #3 (=5) is first, then #1 (=6), then #2 (=7) and finally #4 (=8).

Pass or fail!
ElMaestro
Helmut
★★★
avatar
Homepage
Vienna, Austria,
2024-04-02 12:51
(254 d 00:42 ago)

@ ElMaestro
Posting: # 23930
Views: 5,484
 

 The sort function

Hi ElMaestro,

why not simply sort()?

x <- c(6, 7, 5, 8)
x; sort(x)
[1] 6 7 5 8
[1] 5 6 7 8


Dif-tor heh smusma 🖖🏼 Довге життя Україна! [image]
Helmut Schütz
[image]

The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes
ElMaestro
★★★

Denmark,
2024-04-03 00:44
(253 d 12:49 ago)

@ Helmut
Posting: # 23932
Views: 5,403
 

 The sort function

Hi Helmut,

❝ why not simply sort()?

❝    x <- c(6, 7, 5, 8)

❝    x; sort(x)

❝    [1] 6 7 5 8

❝    [1] 5 6 7 8


Sorting does another thing than what I needed.
I was looking for exactly what rank does, although at the time I wrote the post I did not know this function was there. So I initially thought order was appropriate, and I got very confused about it :-)

It all relates to SaToWIB and the functions that compare two concentration vectors. More shall be revealed :cool:

Pass or fail!
ElMaestro
Helmut
★★★
avatar
Homepage
Vienna, Austria,
2024-04-04 11:39
(252 d 01:53 ago)

@ ElMaestro
Posting: # 23933
Views: 5,443
 

 lag-times of profiles and cor()

Hi ElMaestro,

❝ It all relates to SaToWIB and the functions that compare two concentration vectors…

A word of caution: If you have lag-times, a simple correlation of concentrations might be small even if profiles are very similar. Generate a profile (for simplicity with equally spaced sampling times) and shift the second one. Try this one:

t    <- seq(0, 24, 0.5)
lag  <- 2
c1   <- exp(-log(2) / 4 * t) - exp(-log(2) / 1 * t)                 # no lag-time
c2   <- exp(-log(2) / 4 * (t - lag)) - exp(-log(2) / 1 * (t - lag)) # lag-time
c2[c2 < 0] <- NA
plot(t, c1, type = "l", ylab = "c", las = 1)
lines(t, c2)
data <- data.frame(t = t, c1 = c1, c2 = c2)
m1   <- lm(c2 ~ c1, data = data)
m2   <- lm(c2 ~ c1 * t, data = data)
res  <- data.frame(model = c("Pearson", "simple", "nested"),
                   r.sq  = c(cor(data$c2, data$c1, use = "complete.obs"),
                             summary(m1)$r.squared,
                             summary(m2)$r.squared),
                   r.sq.adj = c(NA,
                                summary(m1)$adj.r.squared,
                                summary(m2)$adj.r.squared))
# shift c2 by the estimated lag-time
c3   <- c2[tail(which(c2 == 0), 1):length(c2)]
c3   <- c(c3, rep(NA, length(c1) - length(c3)))
ski  <- paste("correlation of shifted profiles =",
               cor(c3, c1, use = "complete.obs"), "\n")
print(res, row.names = FALSE); cat(ski)

   model      r.sq  r.sq.adj
 Pearson 0.8059089        NA
  simple 0.6494891 0.6413377
  nested 0.9711260 0.9690133
correlation of shifted profiles = 1

Only in the nested model (taking time into account) we see that profiles are highly correlated.
If you are courageous, estimate the lag-time and shift the profile(s). Of course, this works only with equally spaced intervals, which we never have. Hence, I would opt for the nested model.

# visualize why the simple model is crap
plot(c1, c2, ylab = "c2, c3", las = 1, col = "blue")
abline(coef(m1), col = "blue")
# out of competition
points(c1, c3, col = "red")
abline(lm(c3 ~ c1), col = "red")


Dif-tor heh smusma 🖖🏼 Довге життя Україна! [image]
Helmut Schütz
[image]

The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes
ElMaestro
★★★

Denmark,
2024-04-04 14:30
(251 d 23:02 ago)

@ Helmut
Posting: # 23934
Views: 5,404
 

 Roaster VII/VIII, Bandana Castor, and Effiou

Hi Hötzi,


❝ Try this one:


   model      r.sq  r.sq.adj

 Pearson 0.6732094        NA

  simple 0.4532110 0.4415771

  nested 0.8685853 0.8598244


This would amount to a perfect corr. in other algorithms. Using an approach not unlike jackkniving you can simply do a "shift N time points, then correlate" and iterate over N, or use a subset of N consecutive points from one vector and correlate with N consecutive points from the other vector while starting at position a in vector 1 and starting at position b in the other vector. You'd then iterate over N, a and b. In R, these things take a lot of time, but in C it is really fast. Like a speed gain of a factor 10000 etc.
Detection algos called Roaster VII/VIII, Bandana Castor, and Effiou etc would take care of these cases and a lot of other (possibly imaginary?) stuff, too. No publication detailing these approaches yet; might do it if or when the time is right.

Pass or fail!
ElMaestro
Helmut
★★★
avatar
Homepage
Vienna, Austria,
2024-04-04 15:04
(251 d 22:28 ago)

@ ElMaestro
Posting: # 23935
Views: 5,410
 

 Nomen est omen

Hi ElMaestro,

you’re the king of baptizing stuff. I still have a copy of EFG.

Dif-tor heh smusma 🖖🏼 Довге життя Україна! [image]
Helmut Schütz
[image]

The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes
ElMaestro
★★★

Denmark,
2024-04-04 15:50
(251 d 21:42 ago)

@ Helmut
Posting: # 23936
Views: 5,324
 

 Nomen est omen

Hi Hötzi,

❝ you’re the king of baptizing stuff. I still have a copy of EFG.



I heard in my local supermarket that the author of the SaToWIB software gave it that name as a handy abbreviation of:
Sick and Tired of WHO's Insane Bureaucracy

Since I don't quite know if this is true I tried to call the author a moment ago, but he said in a disgruntled tone that this is absolutely untrue; he'd never do such a thing. But he was knee-deep in paperwork and didn't have time to discuss the matter further.

Pass or fail!
ElMaestro
Ohlbe
★★★

France,
2024-04-04 16:52
(251 d 20:40 ago)

@ ElMaestro
Posting: # 23937
Views: 5,315
 

 Nomen est omen

Hi ElMaestro,

[Off Topic] I'm getting curious about the Bandana Castor name. Castor is French for beaver, so I'm getting a picture of a beaver wearing a bandana, which would be really weird :-D [/Off Topic]

Regards
Ohlbe
ElMaestro
★★★

Denmark,
2024-04-04 18:16
(251 d 19:16 ago)

@ Ohlbe
Posting: # 23939
Views: 5,329
 

 Nomen est omen

Hi Ohlbe,

❝ [Off Topic] I'm getting curious about the Bandana Castor name. Castor is French for beaver, so I'm getting a picture of a beaver wearing a bandana, which would be really weird :-D [/Off Topic]


As you may recall from the Iliad, the fourth book:
Effiou, Castor and Loukaniko fought alongside each other and secured victory at the Battle of Mortadella through a cunning stunt involving Effiou's horse and a guitar. Then Castor stood up on a cliff and shouted to his men: "Ich bin ein Berliner!" and this inspired the men to head for Ithaca.

A few thousand years later the famous rock star and guitar player Carlos Bandana felt inspired by the heroism displayed by Effiou and his men. How many times haven't we all listened to his famous song "Pigs can fly" in sheer joy?

I believe you will completely agree that the names make very good sense in light of the inspired heroism that Carlos Bandana has passed to us all from Effiou, Castor and Loukaniko with this guitar riffs in these troubling times.

Pass or fail!
ElMaestro
nobody
nothing

2024-04-10 11:21
(246 d 02:12 ago)

@ ElMaestro
Posting: # 23946
Views: 5,146
 

 Nomen est omen

Add to TDL: Check medication. Soon...:surprised:


Edit: Full quote removed. Please delete everything from the text of the original poster which is not necessary in understanding your answer; see also this post #5[Helmut]

Kindest regards, nobody
Ohlbe
★★★

France,
2024-04-10 11:34
(246 d 01:59 ago)

@ nobody
Posting: # 23947
Views: 5,125
 

 Nomen est omen

Hi Nobody,

❝ Add to TDL: Check medication. Soon...:surprised:


Why ? ElMaestro's explanation makes perfect sense, it rocks, actually.

In any case, there is nothing that a course of Schützomycin won't cure.

Regards
Ohlbe
nobody
nothing

2024-04-10 12:21
(246 d 01:11 ago)

@ Ohlbe
Posting: # 23948
Views: 5,115
 

 Nomen est omen

❝ Why ? ElMaestro's explanation makes perfect sense, it rocks, actually.


❝ In any case, there is nothing that a course of Schützomycin won't cure.


Cause Loukaniko has never been a Berliner

If any, it's been this guy here

To start with...

Kindest regards, nobody
ElMaestro
★★★

Denmark,
2024-04-11 12:50
(245 d 00:42 ago)

@ nobody
Posting: # 23949
Views: 5,038
 

 Source

Dear all,

as you marvel over my accurate account of important historical events I can add that some of all this was captured on source.

Pass or fail!
ElMaestro
nobody
nothing

2024-04-12 13:46
(243 d 23:46 ago)

@ ElMaestro
Posting: # 23950
Views: 5,038
 

 Source


Kindest regards, nobody
Ohlbe
★★★

France,
2024-04-12 20:23
(243 d 17:09 ago)

@ nobody
Posting: # 23951
Views: 5,028
 

 Inquiry

❝ ...meanwhile in Austria


Reminds me of this

Regards
Ohlbe
nobody
nothing

2024-04-15 11:54
(241 d 01:38 ago)

@ Ohlbe
Posting: # 23953
Views: 4,892
 

 Inquiry

❝ ❝ ...meanwhile in Austria


❝ Reminds me of this


Mildly OT, but this time the problem goes a little deeper with Kickl and Wunderwutzi potentially involved. Have a look where Mr. Wunderwutzi is getting his paycheque nowadays from...

Kindest regards, nobody
UA Flag
Activity
 Admin contact
23,336 posts in 4,902 threads, 1,667 registered users;
27 visitors (0 registered, 27 guests [including 6 identified bots]).
Forum time: 12:33 CET (Europe/Vienna)

Biostatistician. One who has neither the intellect for mathematics
nor the commitment for medicine but likes to dabble in both.    Stephen Senn

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5