I am trying to apply a model to my dataset. The way my response variable has been generated is a bit convoluted but it's been checked by my supervisor - I have strings of numbers (e.g 112222333322111) and I count the length of each run of numbers (1-2, 2-4, 3-4, 1-3). I then find the median length of these blocks (here, the median of 2,4,4,3 so 3.5). This median is my response variable. Thus, the values are all positive and non-zero but can have decimals (rounding wouldn't be appropriate).
A linear model lm(median ~ Nymph + TOD, data = all_median) using an untransformed response indicates a heavy right skew (see attached). I have tried square root, log, inverse and box cox transforming my response variable but I don't get a QQplot that looks remotely normal. I then tried a gamma family with log link function GLM but my model was underdispersed(Residual deviance: 942.32 on 1812 degrees of freedom = 0.52). My predictors are both categorical (Nymph, holding a value of Adult or Nymph) and TOD (AM, MID, PM). I will be including two random effects (ID and Date) but for now, I'm trying to figure out what sort of model to do. As it is, I've run out of things to try. Would a GAM be appropriate, if so how is this done in R?