# How to: GeneralizedLinearModelFit with Dataset with cofactors

Please do not think of this question as a more general extension of LinearModelFit with Dataset asked by @alan, and answered by @Weach.

The original question (or at least the solution) pertained more to how to overload LinearModelFit to work on Dataset.

While overloading GeneralLinaerModelFit for Dataset would be nice; here, however, the question is more in relation to "data wrangling" / how to input my data to get the desired results.

Suppose you have a Dataset as follows:

numberOfRecords = 100;  (* records in the dataset *)

numberOfGroups = 2;    (* groups:    g1,...,gn *)
numberOfSegments = 4;  (* segments:  s1,...,sn *)
numberOfCofactors = 3; (* cofactors: c1,...,cn *)
numberOfFeatures = 5;  (* features  x1,...,xn *)

(* in this case binary *)
responseVector = RandomInteger[{0, 1}, {numberOfRecords, 1}];
groupVector = RandomInteger[{1, numberOfGroups}, {numberOfRecords, 1}];
segmentVector =
RandomInteger[{1, numberOfSegments}, {numberOfRecords, 1}];

featureMatrix =
RandomReal[{-10, 10}, {numberOfRecords, numberOfFeatures}];
cofactorMatrix =
RandomReal[{-10, 10}, {numberOfRecords, numberOfCofactors}];

(* join data together *)
data = Table[
Join[
responseVector[[r]],
groupVector[[r]],
segmentVector[[r]],
featureMatrix[[r]],
cofactorMatrix[[r]]
], {r, numberOfRecords}
];

{"y", "g", "s"},
Table["x" <> ToString[i], {i, 1, numberOfFeatures}],
Table["c" <> ToString[i], {i, 1, numberOfCofactors}]
]

(* map header to each record *)
(* make dataset *)
ds = Dataset@assoc;


The goal is to do the following:

per group, taking into account the cofactors, predict the response at each segment.

So the result should look something like this (given the demo data) From the Details and Options tab of the documents, I can not really see how I should format my data to get the results I am looking for. Any help and explanation would be greatly appreciated.

• How do you plan to "predict the response at each segment.". I don't really want to dig to figure out how you expect that to happen (and I'm guessing not many others want to either). – b3m2a1 Feb 13 '18 at 22:03