Tuesday, 13 March 2018

Decision trees for UK voting

The next data-analysis method I'm playing with is decision-tree regression.

It's a method often said to be included in a field of statistical computing (called machine learning, statistical learning, artificial intelligence, data mining, supervised learning, etc). Decision trees usefully split up datasets into groups, often using YES/NO questions at each split.

I'm using data from Qriously (date 2017-06-07) in the run-up to the UK general election. I'm looking only at England & Wales, and I've only considered 3 regressors: gender (0=F, 1=M), age, income. I've considered a YES/NO voting intention for the 5 biggest political parties.

The trees are below. Here are some key aspects that jump out:
  • Age seems to be the most important regressor for most parties.
  • CON seems to get many votes from older voters (except if they're poor).
  • CON gets few votes from younger votes (especially poorer voters).
  • CON's best group were older females (not males as one might expect - maybe this is simply a bias of longer life expectancy for females).
  • LAB/CON results are fairly inverted (as we might expect), i.e. poorer and younger voters favouring LAB. 
  • LAB's best group were young, poor females.
  • LAB's worst group are the 65+.
  • LIB seems to do best from low- and middle-income voters, more-so for male voters.
  • LIB's two worst groups are from (a) elderly richer females, and (b) poorer older voters.
  • GRN's voters are generally younger (the one exception being wealthier older females) -- young males is one key group.
  • GRN does badly with (a) older, poorer voters and (b) older, richer males.
  • UKIP voters are generally poorer. One key group being poorer younger males.
There are so many assumptions and drawbacks in these sorts of analyses - but anyway, interesting all the same.


CON: 


LAB: 

LIB: 

UKIP: 

GRN: 

Wednesday, 7 March 2018

Logistic regression

The next data-analysis method I'm playing with is logistic regression (LR).

It's a method often said to be included in a field of statistical computing (called machine learning, statistical learning, artificial intelligence, data mining, unsupervised learning, etc). LR is mostly used in cases of yes/no classifications.

I'm trying to use data from my previous blogs where possible. So the dataset is not really super suitable for LR (I don't believe I could really use the model result to predict the probability of future undisturbed nights of sleep) - but I'll use it anyway as a data-exploration tool. The data are taken from camera imagery of our baby/toddler's sleep each night (see earlier blog posts).


It is probably possible to estimate, by eye from the red crosses, that there have been more undisturbed nights of sleep in the later months. But the logistic regression makes it clear that there is a positive relationship - i.e. our baby/toddler is sleeping through more and more nights (apparently sleeping through most nights by the end of the year).

Tuesday, 6 March 2018

k-means clustering

I want to play with data. In this case I want to find regimes/clusters in a dataset I saw in book "The Spirit Level" from the Equality Trust. I took the data (year 2010) from GapMinder (Hans Rosling is an idol of mine!).

It's a method in a field of statistical computing (called machine learning, statistical learning, artificial intelligence, data mining, unsupervised learning, etc). The method is called k-means clustering. 'k' simply refers to the number of groups (clusters) in the dataset.

In this case the idea is that once a country reaches a certain level of wealth (about 5000-10000 USD/capita), no longer does life expectancy increase much (or at all) any more with still further increases in wealth.

k=3. When I was at school we were taught mostly about three worlds: under-developed, emerging and developed economies. So the first group includes countries like Mozambique, Malawi, Afghanistan. The second group Russia, India, Chile, China. The final group most western countries (USA, UK, Germany, etc).

k=9. Interestingly with more clusters small features start to emerge, like a group for South Africa and Botswana where increases in wealth have not translated into increases in life expectancy.

With k-means typically equal-size clusters are typical, so small clusters don't emerge, e.g. Bermuda and Luxembourg as the two most-rich per-capita countries.

Monday, 5 March 2018

k-nearest neighbour

I previously made some observations of lake depth in central Finland and plotted them in octave. I let octave use its own smoothing and interpolation between my datapoints. Now I'm curious to look a little at a simple algorithm of my own.

It's a simple method in a field of statistical computing (called machine learning, statistical learning, artificial intelligence, data mining, supervised learning, etc). The method is called k-nearest neighbours. 'k' simply refers to the number of nearest neighbours one takes into account.

Tuesday, 8 August 2017

Lake temperature in central Finland








(earlier posts 1,2 on the methods)

Thursday, 15 June 2017

Paternity leave (isyysvapaa) and me as a stay-at-home parent (SAHP) for Jan-June 2017

The 'data' in this post is anomalous - it's qualitative/experiential. I'm not requesting any replies. I just felt the need to write down some of my feelings, opinions and experiences. I thought that others might be interested to read.
I felt that I MUST stay at home for months raising Zadie in order to match our values:
 - for my new family (Zadie and Annika) i.e. we're no longer in 19/20th century forcing mother to stay at home alone for years and go mad;
 - to provide a closer father for Zadie;
 - to be part of modern society where fathers are allowed to be SAHPs too!

According to KELA statistics in Finland, and depending exactly how one defines it, the ratio of SAH Moms/Dads seems to be between about 60/40 and 90/10. This seems about right to me at least based on the families we've seen.

I decided to focus on Zadie - and I'm very grateful I am not using up my energies on domestic things in my 'new job':
 - Cleaning is done by a cleaner twice a month.
 - Groceries are bought on the internet and delivered to our door.
 - I cook only very rarely; otherwise we eat out, or Annika cooks, or we have something light.
 - Laundry I occasionally do during the day, but we normally do it together at evening/weekend.
 - Zadie's clothes, toys, accessories are mostly done by Annika (or together) via flea markets.

If I do have spare time during the day (e.g. Zadie has napped for an hour or more), then I'm glad that I've often had time to do something for myself such as contacting a friend or spending some time on a geeky hobby (delectabledata.blogspot.com).
 - Analysis of Zadie's night-time sleep with the night-vision camera.
 - Automatic logging of lake temperature at the cabin/mökki.

My mental energy has been mostly filled with basic care things like Zadie's sleep, food and safety. It can be hard to remember to have fun with Zadie - when Annika comes home is so lovely to see the two of them often play/laugh together.

SAHP has felt very natural in many ways. Not at all as bad as I was fearing. My 5 months of SAHP has gone by fast. Although it has still been a challenge of course - returning to work will be easy after this! For the SHAP, there are dozens/hundreds of little considerations/tasks/plans. SAHPing can be very emotionally/analytically demanding. I often feel overwhelmed by the constant challenges, changes and failures, e.g. it has often been difficult to get Zadie to spend any time in the pram. SAHPing has been a great opportunity to have a sizeable break from work; I'm excited to see how my work-life changes in the future after this SAHP experience.

I've been more in contact with own feelings:
Happy tears:
 - My first working day with Zadie ('muskari' at Linja).
 - Zadie's first claps.
 - Sometimes just holding her in my arms.
 - Zadie's first steps.
 - When on holiday together - it's lovely the 3 of us.
Anger:
 - I've shouted with anger. Of course I'm not thinking clearly when e.g. I'm tired, I have too high expectations, a 100hr+ working week, and being human. Then follows guilt that this is too much for Zadie. I'm told that this is common in parenting - but somehow this doesn't help me much.

When I'm angry, part of it is really a feeling of fear that I'm a bad father. Of course it is not nice, but it happens. People have emotions. And there is a crumb of positive here in that Zadie gets to see a real/wholehearted/emotional person. Possible mantra: I'm a good-enough father.

Lack of control is annoying. E.g. I've just got Zadie to sleep, then there's a loud sound and it wakes her. Frustrating. Of course it's totally normal to feel disappointed/annoyed/negative in those situations, but it just feels too much sometimes. Though when looking back later that same day, I can see it didn't really matter that much after all! The benefit of hindsight and perspective!

I give myself a hard time with failure (e.g. Zadie in pram). I want perfection. I find it hard to just be happy that I tried and sometimes it works, sometimes not. As my father wisely said: childcare cannot be solved by equations, so stop trying.

Lots of change. Challenging. The support of Annika is lovely. Although sometimes feel guilty for needed it - how strange as she's my wife, friend and mother of my child. Probably a general theme about my not asking for help enough?

Nappy changes. For some reason I thought nappy changes would somehow be too challenging. They're not. A blessing! The vast majority of the time it's as simple as flicking a light-switch. In fact sometimes any part of baby-care can be easy peasy; but at other times those same things can feel insurmountable. Furthermore, on some days it can be difficult even to find time to get out of pyjamas, much less have a shower or eat properly.

It has too often felt lonely for me. I even put out a request for help on Facebook and it was lovely to get so many replies which made me feel less lonely. Though when I've later asked people one-to-one for spontaneous help most people's calendars are full - perhaps this is a peculiarity of modern busy scheduled life? Anyway, humans are mammals and surely babies should be brought up in a pack/tribe/community; it feels so unnatural to shut a parent indoors with babies/children for several years. Although luckily we've been out most days, often to the excellent city facilities like playgroup (singing, playing, eating, chatting with other SAHPs). But we have been fortune to have opportunities with neighbours, visits to other countries, cities, museums, galleries, shops, nature, baby cinema, swimming, baby massage, etc. It so easy getting around by bus and especially train - whilst travelling one can go to restaurant, toilet, play area, etc. To us using a car seems a more difficult option.

We have actually met lots of people and I've even kept my Finnish language skills brushed up. It is lovely to have a network of acquaintances. And it's easier to speak with random people in day-to-day life when I'm with Zadie. Although I'm often wishing to find people who I can connect much better/deeper with.

I've also enjoyed getting involved in community work with Zadie at my side. I've volunteered at Kalliolan setlementti by teaching (in Finnish) mathematics and Finnish to small groups.

There is so much advice out there on parenting. And people often seem so sure of it - I guess unsure people keep quiet. But when I ask people for the source/reference/evidence, there normally is not one. With my scientific training, my mind wants to know whether something really has any chance of working or not and whether it will have any lasting effect (?damage) on our baby. I find it a challenge to just 'trust' myself as a parent when in society we get trained/licences/support for so many things we do. But babies seem to be mostly a lighter and own-values-based approach. I could think in circles for hours on these things, so I won't.

We're happy that we've avoided TV. There were perhaps 2-3 taxi rides where she was very upset and we used some YouTube nursery rhymes to help her cope with the taxi ride. But that's about it.

I've been virtually 24/7 with Zadie for many months in a row. Strange. I have enjoyed a 'night off' sleeping away from home: a nice medicine/luxury to relax.

We've been ill a lot - about once a month. Flus, colds, tummy bugs. Yuck.

I'm grateful that Annika works normal (8am-4pm) workdays and does not work at home and very rarely travels for work. It's a great support for me, and of course it's great for Zadie--Annika relationship too. I've not found myself clock watching to count the hours until Annika comes home.

The new-born phase is now a distant dream - I can't quite remember it. I'm looking forward to when Zadie can talk with us and do cool things like baking.

The whole SAHP experience gives perspective in so many ways. One mundane thing is simply not worrying so much about stains on clothes, queues of laundry, dirty dishes, etc. There just isn't always time to sort out these things immediately any more. Even though I knew, or could have guessed, most of what I've written about being a SAHP - it's still an extra level of understanding to walk in the shoes of a SAHP. Certainly a training in empathy.

I love Zadie and Annika very much, and I surely now have more understanding/love/compassion for myself. I'm very happy to be Zadie's father and I hope we have a close relationship as she grows up. Bring on Life 2.0.

Thursday, 11 May 2017

Baby's sleep statistics

Here are a few graphs, made in octave, of the development of our baby's sleep in recent months.
(see my earlier post for details about _how_ the data were collected)

  1. Falling to sleep typically varies around 0-60 minutes.
    Here, we are not including the bed-time routine of food, bath, soft music, turn lights down, pyjamas, etc. So here is an estimate of the time from first trying to put the baby down in the cot until asleep (i.e. no major movements). 
  2. Bedtime varies between 7 and 10pm, but clearly depends a lot when us parents chose to try to put the baby to sleep (hence there being many nights just after 8pm).
  3. Wake-up time varies between 5 and 8am.
    Again, is the baby wakes before 5am, we try hard to put her back to sleep - hence nothing before 5am.
  4. Sleep duration varies between 8 and 12 hours per night.
  5. The number of wakes per night varies between about 0 and 8.
    Yes, the baby sometimes sleeps _all night_ without waking.