ElMaestro
★★★

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

(edited by on 2024-03-24 18:24)
Posting: # 23918
Views: 832
 

 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
(18 d 19:00 ago)

@ ElMaestro
Posting: # 23919
Views: 742
 

 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
(18 d 18:19 ago)

@ ElMaestro
Posting: # 23920
Views: 737
 

 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
(16 d 19:33 ago)

@ ElMaestro
Posting: # 23925
Views: 657
 

 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
(16 d 06:47 ago)

@ d_labes
Posting: # 23927
Views: 641
 

 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
(10 d 04:40 ago)

@ ElMaestro
Posting: # 23930
Views: 508
 

 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
(9 d 16:47 ago)

@ Helmut
Posting: # 23932
Views: 499
 

 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
(8 d 05:52 ago)

@ ElMaestro
Posting: # 23933
Views: 460
 

 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
(8 d 03:01 ago)

@ Helmut
Posting: # 23934
Views: 432
 

 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
(8 d 02:26 ago)

@ ElMaestro
Posting: # 23935
Views: 422
 

 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
(8 d 01:40 ago)

@ Helmut
Posting: # 23936
Views: 410
 

 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
(8 d 00:39 ago)

@ ElMaestro
Posting: # 23937
Views: 398
 

 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
(7 d 23:15 ago)

@ Ohlbe
Posting: # 23939
Views: 382
 

 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
(2 d 06:10 ago)

@ ElMaestro
Posting: # 23946
Views: 176
 

 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
(2 d 05:57 ago)

@ nobody
Posting: # 23947
Views: 168
 

 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
(2 d 05:09 ago)

@ Ohlbe
Posting: # 23948
Views: 158
 

 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
(1 d 04:41 ago)

@ nobody
Posting: # 23949
Views: 87
 

 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
(03:45 ago)

@ ElMaestro
Posting: # 23950
Views: 33
 

 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.


...meanwhile in Austria: https://correctiv.org/aktuelles/russland-ukraine-2/2024/04/12/marsalek-wirecard-und-der-russische-geheimdienst-was-wusste-der-ehemalige-geheimdienstkoordinator-bernd-schmidbauer/

Kindest regards, nobody
UA Flag
Activity
 Admin contact
22,980 posts in 4,821 threads, 1,655 registered users;
33 visitors (0 registered, 33 guests [including 14 identified bots]).
Forum time: 17:31 CEST (Europe/Vienna)

Never, never, never use any software!
Never, never, never trust any computer!    Detlew Labes

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