Verden er ved at gå under. Og vi arbejder hjemmefra.
Observationer:
Det er stadig ikke muligt at deltage i to møder samtidig.
Det har chefen stadig ikke opdaget
I stedet for at finde ud af hvilke møder der kunne være klaret med en email, finder vi nu ud af hvilke emails der åbenbart skal klares med et online møde.
The pipe-operator %>% takes whatever is on the left-hand-side, and inserts it as the first variable in whatever is on the right-hand-side.
What is on the right-hand-side is the ggplot function. That would normally have a datat=something as the first variable. Here that is the data we constructed earlier.
To that initial plot, which is completely empty, we add a geom_bar. That plots the bars on the plot. It takes an x-value, name, and a y-value, mean. And we tell the function, that rather than counting the number of observations of each x-value (the default behavior of geom_bar), it should use the y-values provided. We also want a nice lightblue color for the bars.
To that bar-chart, we now add errorbars. geom_errorbar needs to know the x- and y-values of the bars, in order to place them correctly. It also needs to know where to place the upper errorbar, and the lower errorbar. And we supply the information that ymin, the lower, should be the mean value minus the standard deviation. And the upper bar, ymax, the sum of the mean and sd. Finally we need to decide how broad those lines should be. We do that by writing “width=0.1”. We do not actually have to, but the default value results in an ugly plot.
And there you go, a barchart with errorbars!
Next step
That was all very nice. However! We do not usually have a nice dataframe with means and standard deviations calculated directly. More often, we have a dataframe like this:
I’ll get back to what the code actually means later.
Here we have 32 observations (only 6 shown above), of the variables “cyl” and “disp”. I would now like to make a barplot of the mean value of disp for each of the three different values or groups in cyl (4,6 and 8). And add the errorbars.
You could scroll through all the data, sort them by cyl, manually count the number of observations in each group, add the disp, divide etc etc etc.
## # A tibble: 3 x 3
## cyl mean sd
## <dbl> <dbl> <dbl>
## 1 4 105. 26.9
## 2 6 183. 41.6
## 3 8 353. 67.8
mtcars is a build-in dataset (cars in the us in 1974). I send that, using the pipe-operator, to the function remove_rownames, that does exactly that. We don’t need them, and they will just confuse us. That result is then send to the function select, that selects the two columns/variables cyl and disp, and discards the rest. Next, we group the data according to the value of cyl. There are three different values, 4, 6 and 8. And then we use the summarise function, to calculate the mean and the standard deviation of disp, for each of the three groups.
Now we should be ready to plot. We just send the result above to the plot function from before:
I think it is ugly. But whatever floats your boat.
Then there is just a vertival bar, geom_linerange. I think it makes it a bit more difficult to compare the errorbars. On the other hand, it results in a plot that is a bit more clean:
Rigsdagsbygningen – historie i læssevis. Og man kan komme op i kuplen. Har vi hørt. Man skal booke adgang online. Og det er en meget omstændelig proces. Så gør det i meget god tid! Stiller man sig i kø (og det gør man også i god tid inden de åbner), så er der adgang sen aften. Det skal man ikke være ked af – Berlin gør sig godt ved nattetide.
Vi er glade for jazz. Og vi blev ganske fornøjede med ATrane, der har livemusik flere gange om ugen: www.a-trane.de
Interessant – og meget anbefalelsesværdig brunch: House of small wonder. Japansk-europæisk fusionsmorgenmad.
Det naturhistoriske museum. Klassiske museumsdyder. Og en ganske imponerende samling af dinoer, blandt andet Tristan, et imponerende T Rex skelet. Deres samling af vådpræparater er efter vores mening rigelig grund til at besøge museet, selv hvis man ikke er interesseret i dinoer.
Hvor spiser man? Rotisserie Weingrün på Gertraudenstrasse 10 i mitte er afsindig godt. Men nu gå jeg også gerne efter steder der har brisler på menuen.
Einstein unter den linden er også ok. Det er www.einstein-udl.com
What is the smallest, positive, number that can be divided by all numbers from 1 to 20 without any remainder?
We are given that 2520 is the smallest that can be divided by all numbers from 1:10.
One number that can definitely be divided by all numbers from 1:20 is:
factorial(20)
## [1] 2.432902e+18
But given that
factorial(10)
## [1] 3628800
is rather larger than 2520, it is definitely not the answer.
The answer must be a multiple of all the primes smaller than 20. A number that is divisible by 15, will be divisible by
3 and 5.
The library “numbers” have a lot of useful functions. Primes(20) returns all primes smaller than 20, and prod() returns the product of all those primes
library(numbers)
prod(Primes(20))
## [1] 9699690
Could that be the answer?
What we are looking at is the modulo-operator. 9699690 modulo 2 – what is the remainder? We know that all the remainders, dividing by 1 to 20 must be 0.
prod(Primes(20)) %% 2
## [1] 0
And our large product is divisible by 2 without a remainder.
Thankfully the operator is vectorized, so we can do all the divisions in one go:
9699690 %% 1:20
## [1] 0 0 0 2 0 0 0 2 3 0 0 6 0 0 0 10 0 12 0 10
Nope.
9699690 %% 4
## [1] 2
Leaves a remainder.
(2*9699690) %% 4
## [1] 0
Now I just need to find the number to multiply 9699690 with, in order for all the divisions to have a remainder of 0.
That is, change i in this code until the answer is true.
i <- 2
all((i*9699690) %% 1:20 == 0)
## [1] FALSE
Starting with 1*9699690, I test if all the remainders of the divisions by all numbers from 1 to 20 is zero.
As long as they are not, I increase i by 1, save i*9699690 as the answer, and test again.
If the test is TRUE, that is all the remainders are 0, the while-loop quits, and I have the answer.
i <- 1
while(!all((i*9699690) %% 1:20 == 0)){
i <- i + 1
answer <- i*9699690
}
Der er pride. Eller, det var der da jeg gik i gang med at skrive det her. Jeg bliver nok ikke færdig inden det er slut. Men jeg tror indholdet vil være gyldigt nogle år endnu.
Vi har et par udfordringer i år. Det er der hvert år. Denne gang er en af sagerne følgende: En kunstner skulle have været på scenen. Hun udtalte at Priden ikke gjorde sit arbejde, og at det er bullshit at Infernal er blevet booket som hovednavn. Infernal er nemlig ikke et LGBT-band. Kunstnerne er ikke LGBT-personer. Og Priden burde, efter hendes mening, kun have LGBT-kunstnere som hovednavne. Hvorefter hun opremser en række LGBT-kunstnere, som jeg aldrig har hørt om. Ikke at mit begrænsede kendskab til musikbranchen skal lægge dem til last, men definitionen på et hovednavn er lidt at det er kunstnere som folk kender.
Og så kom hun ikke på scenen alligevel. Man kan læse mere her.
Hvorfor er det et problem? Ja, det giver uro i miljøet, det tager opmærksomhed fra festlighederne, og det politiske indhold. Men den overordnede problemstilling dukker op igen og igen:
LGBT-separatismen. Den strømning, der argumenterer for at kun LGBT-kunstnere må komme på scenen. Og for en masse andre ting i samme grundlæggende retning.
Og det giver knaster, for separatisterne ønsker at udelukke heteroseksuelle kunstnere. Kritikken bliver ofte intersektionel. For det er også “problematisk” at det overvejende er hvide cis-kønnede kunstnere der er på scenen.
Det er selvfølgelig en kritik der har noget for sig. Det er en LGBT-festival. Så hvorfor skal heteroseksuelle kunstnere på scenen? Det er en mangfoldighedsfestival, så hvorfor kun, eller altovervejende, hvide kunstnere? Og hvorfor ikke også flere transkønnede kunstnere? Og her opstår den første modstrid, den første inkonsistens, der giver problemer. Kan en mangfoldighedsfestival bevidst udelukke heteroseksuelle kunstnere? Afhængig af opgørelsesmetoder, er ca. 90% af befolkningen heterosexuelle. Hvor mangfoldig er en festival hvis den bevidst fravælger 90% af befolkningen? Alene baseret på deres seksuelle orientering?
Lige her finder vi, efter min knap så ydmyge holdning, en af årsagerne til at LGBT-bevægelsen bliver udsat for hån, spot og latterliggørelse. Argumentet er: “I kræver mangfoldighed, men vælger selv at udelukke størstedelen af befolkningen alene på grund af deres seksuelle orientering. Det hænger jo ikke sammen.”
Den mere radikale udlægning af separatismen klager også over at der ikke er flere farvede personer, eller Persons Of Color (POC) på scenen. Det er jo også et reelt argument. En mangfoldighedsfestival kan naturligvis ikke være ensfarvet. Men argumentet udarter ofte til en kritik af at der er “hvide mennesker” på scenen. Definitionen af racisme er normalt at man forskelsbehandler på baggrund af hudfarve. Når (dele af) LGBT-bevægelsen bruger ordet “hvid” pejorativt, lyder det for en traditionel opfattelse af racismebegrebet ret, nåja, racistisk.
Så LGBT-separatisterne mødes naturligvis med hån, spot og latterliggørelse. Argumentet er “I kæmper mod forskelsbehandling af mennesker baseret på deres hudfarve. Og dog udtaler I jer negativt om folk på baggrund af deres hudfarve – så længe den hudfarve er hvid. Det hænger jo ikke sammen.” Og det gør det jo ikke.
En af de ting der ser ud til at ske er, at dele af LGBT-miljøet importerer retorik og problemstillinger fra primært USA. Og selvom vi har rigeligt at kæmpe med i Danmark, så er der en noget større pulje af problemer for LGBT-personer i USA. Men det bliver ofte lidt mærkeligt, når aktivister i Danmark begynder at bekæmpe problemer der i det væsentlige ikke, eller kun i meget begrænset omfang, relativt set, faktisk findes i Danmark. Mit pt foretrukne eksempel er fokus på BIPOC-personer. De er særligt undertrykte i Danmark. BIPOC står for “Black, Indigenous & People of Color”. Og ja, personer i Danmark der har en anden hudfarve end hvid møder mange udfordringer, ikke mindst regulær racisme. Men indegenous. Det betyder indfødte. Indfødte personer er efter den logik særligt undertrykte og udsatte i Danmark. Hvis vi definerer Danmark som rigsfællesskabet er der lidt om det. Grønlændere er vitterligt undertrykte og udsatte i Danmark.
Men går man ud i offentligheden, og taler om hvor hårdt indfødte i Danmark har det, lyder det ærligt talt lidt underligt. De indfødte i Danmark er danskerne. I hvert fald i Syddanmark, den del der ikke er Grønland og Færøerne. Uanset hvor meget oprindelige amerikanere, i daglig tale indianere, måtte have af udfordringer, så er de ikke indfødte i Danmark. Det bliver, måske ikke overraskende, opfattet som meget besynderligt i den brede befolkning her til lands. Hvad værre er, man taler om det på en måde, hvor man fodrer den højreekstreme, etno-nationalistiske bevægelse i Danmark. Den mener jo netop at de indfødte i Danmark er udsatte og truede. En del af dem hiver faktisk fat i indianernes udfordringer i USA. “Se hvad der skete med den oprindelige befolkning i Nordamerika da der kom indvandrere til kysterne. Det samme kommer til at ske med os danskere, når muhammedanerne invaderer os.” er fortællingen.
Vi kommer ikke i LGBT-bevægelsen til at undgå kritik. Vi har nogle dagsordener, der udfordrer det etablerede og sætter spørgsmålstegn ved normer. Det vil naturligt medføre en reaktion. Men vi kan vælge at lade være med at gøre det vanskeligere for os selv, ved at åbne flanker for angreb. Når der er selvmodsigelser i vores argumentation, gør vi det for let for vores modstandere. Ovenstående er bare et meget lille udvalg af inkonsistenserne. Vi kan heller ikke både argumentere for at køn udelukkende er socialt konstruerede, men samtidig så endogene og medfødte som det logisk følger af retorikken om transkønnede. Eller at det er meget urimeligt at store virksomheder ikke viser deres støtte til LGBT-miljøet, samtidig med at vi kritiserer den når de så gør det. Eller at forskelsbehandling på grund af køn er meget forkert, samtidig med at “mænd” bruges som skældsord. Eller at det på den ene side er meget vigtigt at der ikke er nogen der sætter etiketter på andre, og at folk selv skal have lov at definere hvad de er, samtidig med at vi kritiserer Simon Emil Ammitzbøll-Bille og Tommy Ahlers for ikke at kalde sig selv panseksuelle.
Eller. Selvfølgelig kan vi argumentere for både det ene og det andet. Men vi skal holde op med at mene, at når modstriden bliver eksponeret og problematiseret, så er det fordi de der gør det er onde og reaktionære. Det er de sikkert også. Men det skyldes også at vores argumenter ikke altid hænger specielt godt sammen. Det første er en lang kamp at gøre noget ved. Det tager tid at flytte folks holdninger, og det er grundlæggende kun dem selv der kan flytte sig.
So we got to rent a new room in the cellar. It is a bit exposed, and we are not absolutely sure that it is actually frost-free. Or how humid the room is for that matter. How to track that? An arduino with a digital thermometer? With an SD-card reader? Or a Raspberry Pi?
The problem is that the room is too far from our appartment ruling out something connected to the internet – unless I want to go full IoT and set up something with a mobile connection.
After a couple of hours considering this, I came up with this basic plan:
Connect a digital thermometer and hygrometer to a Raspberry Pi Zero.
Write something that reads the values, and collect the data.
Write something else, that tries to connect to a mobile hotspot from my cell-phone.
When the connection is made – dump the collected data somewhere.
Make sure that you pass the room on a regular basis with the mobile hotspot active.
How to do that? I already had a Raspberry Pi Zero v 1.1 lying around. It has build-in wifi. First step is to set it up with a fresh SD-card:
Download the Raspbian Buster Lite image from https://www.raspberrypi.org/downloads/raspbian/
Inset the sd-card in the computer, and follow the instructions on https://www.raspberrypi.org/documentation/installation/installing-images/README.md. I already had Balena Etcher installed.
Next, it would be nice to connect to it via USB, rather than connecting the Pi to a screen and work directly on it. In order to be able to do that, I go to the boot-folder on the newly flashed SD-card. There I do this:
add the line “dtoverlay=dwc2″ at the very bottom of config.txt
Open the file cmdline.txt, locate the parameter “rootwait” and immediately after that, add this “modules-load=dwc2,g_ether”.
Make af file called “ssh”
Now, in principle, you move the sd-card to your Pi, connect it to the UBS-port on your computer, and you should be able to ssh into pi@raspberrypi.local, using raspberry as the password.
However, it is not quite that simple. When the Pi has been connnected to the laptop, go to settings, choose the wired connection, choose IPV4, and change the “method” to only link-local (do the same for IPV6). And under Identity, change the name to raspberrypi.local.
And now we can ssh into it.
Next step is to get some temperature and humidity readings.
For that purpose, I’m using a DHT22 sensor. More specifically an already wired up sensor. It has four connections, but I’m only using three. The red wire, power is connected to a 3.3V, the black wire to ground, and the yellow data-wire to any GPIO pin. I’m using pin 2
Next – after the Pi is again connected to power, and I have SSH’ed into it, some packages need to be installed.
Before that can be done, I need to get it connected to wifi.
As I am going to use my cell-phone for that I set that up to provide a hotspot. The ssid (or name of the hotspot) is set to NusseMobil, and the password to 3.141592653.
Then I edit the file /etc/wpa_supplicant/wpa_supplicant.conf file on the Pi:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
And add this to the end of the file:
network={
ssid=”NusseMobil”
psk=”3.141592653″
Then I run this command:
wpa_cli -i wlan0 reconfigure
to get the Pi to take in the new network configuration.
Testing: Unplug the Pi from the laptop, and connect it to a separate power source. Does the Pi connect to the hotspot? If so, stuff is working, and I plug it into the laptop again.
Now I ssh into the Pi, make sure that there is live connection to the web (ping www.dr.dk is the standard way in Denmark to test that)
Within the file is a mail-adress. I make a new google drive sheet, and share it with that mailadress.
editing the example from the package:
sudo nano google_spreadsheet.py
I add json filename and spreadsheet name
And try to run it:
sudo ./google_spreadsheet.py
Nope! A couple of packages are still missing:
pip install gspread
pip install –upgrade oauth2client
And then I can run it. I get an error telling me that I have forgotten to activate the API. Luckily the error provides the link I need to go to.
And after a couple of minutes the change has propagated through Googles servers, and things are working. The spreadsheet are now steadily being populated with temperature and humidity readings every 30 seconds.
Nice!
How long can I run it on batteries?
That depends on how much power is drawn by the Pi.
An interesting observation. Please note that I have absolutely no idea about why this happens. (at least not at the time of first writing this)
In our datalab, ingeniuously named “Datalab” (the one at KUB-North, because contrary to the labs at the libraries for social sciences, and for the humanities, we are not allowed to have a name), we were visited by at student.
She wanted to make a dose-response plot. Something about the concentration of something, giving some clotting of some blood. Or something…
Anyway, she wanted to do a 4-parameter logistic model. Thats nice, I had never heard about that before, but that is the adventure of running a datalab, and what makes it fun.
Of course there is a package for it, dr4pl. After an introduction to the wonderful world of dplyr, we set out to actually fit the model. This is a minimal working example of what happened:
if(!is.numeric(dose)||!is.numeric(response)) {
stop("Both doses and responses should be numeric.")
}
Lets try:
if(!is.numeric(data$dose)||!is.numeric(data$response)) {
stop("Both doses and responses should be numeric.")
} else {
print("Where did the problem go?")
}
## [1] "Where did the problem go?"
No idea. Did it disappear? No:
dr4pl(data, dose, response)
## Error in dr4pl.default(dose = dose, response = response, init.parm = init.parm, : Both doses and responses should be numeric.
Looking at the data might give us an idea of the source:
str(data)
## Classes 'tbl_df', 'tbl' and 'data.frame': 10 obs. of 2 variables:
## $ dose : int 1 2 3 4 5 6 7 8 9 10
## $ response: int 2 3 4 5 6 7 8 9 10 11
Both dose and response are integers. Might that be the problem?
data <- tibble(dose= (1:10)*1.1, response = (2:11)*1.1)
dr4pl(data, dose, response)
## Error in dr4pl.default(dose = dose, response = response, init.parm = init.parm, : Both doses and responses should be numeric.
Nope. Both dose and response are now definitely numeric:
str(data)
## Classes 'tbl_df', 'tbl' and 'data.frame': 10 obs. of 2 variables:
## $ dose : num 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 11
## $ response: num 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 11 12.1
Find six four-digit numbers that are cyclical. As in: The last two digits of the first number is equal to the first two digits of the second number, the last two digits for the second number is equal to the first two digits in the second number. Etc. The last two digits in the final sixth number must be equal to the first two digits in the first number.
Also, one number must be triangle, one square, one pentagonal, one hexagonal, one heptagonal and on octagonal.
Lets begin by making lists of the different kinds of numbers:
Four-digit triangle-numbers:
P3 <- function(x){
x*(x+1)/2
}
L3 <- P3(45:140)
Square numbers:
P4 <- function(x){
x*x
}
L4 <- P4(32:99)
Pentagonal:
P5 <- function(x){
x*(3*x -1)/2
}
L5 <- P5(26:81)
Hexagonal
P6 <- function(x){
x*(2*x-1)
}
L6 <- P6(23:70)
Heptagonal:
P7 <- function(x){
x*(5*x-3)/2
}
L7 <- P7(21:63)
Octagonal:
P8 <- function(x){
x*(3*x-2)
}
L8 <- P8(19:58)
Lets get them all into a list:
values <- list(L8, L7, L6, L5, L4, L3)
And this is where it gets complicated.
I take each value in L8, which is now values[[1]]
For each of them, I run through each of the other elements of values, 2:6.
For each values[[i]], I check if there are any of the numbers, where the first two digits is equal to the last two in the element in L8 I’ve come to.
If there is, I run through all of them (the ones where the first two digits is equal to the last two in the element in L8 I’ve come to.)
For each of these, I run through each of the remaining list elements, setdiff(2:6, b), where b is the iterator in 2:6
For each of those, I check that there are numbers where the first two digits etc etc etc.
When I get to the last number, I check that the last two digits are the same as the first two digits in the number in the first loop. Then I sum the numbers I’ve found, and get the answer.
It is not difficult. As such. But there are a lot of nested for-loops, and I have to check that there is a possible next number, and, if not, go to the next element.