```/* nag_blgm_lm_formula (g22yac) Example Program.
*
* Copyright 2017 Numerical Algorithms Group.
*
* Mark 26.2, 2016.
*/
/* Pre-processor includes */
#include <stdio.h>
#include <string.h>
#include <nag.h>
#include <nag_stdlib.h>
#include <nagg22.h>

#define MAX_FORMULA_LEN 200
#define MAX_VNAME_LEN 200
#define MAX_CVALUE_LEN 200

#define DAT(I,J) dat[j*lddat+i]
#define X(I,J) x[j*ldx+i]

int main(void)
{
/* Integer scalar and array declarations */
Integer i, j, ivalue, lddat, ldx, lvnames = 0, mx, nobs, nvar,
sddat, sdx, lcvalue;
Integer exit_status = 0;
Integer *levels = 0;

/* Nag Types */
NagError fail;
Nag_VariableType optype;

/* Double scalar and array declarations */
double rvalue;
double *dat = 0, *x = 0, *y = 0;

/* Character scalar and array declarations */
char cvalue[MAX_CVALUE_LEN], formula[MAX_FORMULA_LEN];
char **vnames = 0;

/* Void pointers */
void *hform = 0, *hddesc = 0, *hxdesc = 0;

/* Initialize the error structure */
INIT_FAIL(fail);

printf("nag_blgm_lm_formula (g22yac) Example Program Results\n\n");

/* Skip heading in data file */
scanf("%*[^\n] ");

/* Read in the formula for the full model, remove comments and */
/* call nag_blgm_lm_formula (g22yac) to parse it */
nag_blgm_lm_formula(&hform,formula,&fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_blgm_lm_formula (g22yac).\n%s\n", fail.message);
exit_status = 1;
goto END;
}

/* Call nag_blgm_optget (g22znc) to extract the parsed formula */
lcvalue = MAX_CVALUE_LEN;
nag_blgm_optget(hform,"Formula",&ivalue,&rvalue,cvalue,lcvalue,&optype,
&fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_blgm_optget (g22znc).\n%s\n", fail.message);
exit_status = 1;
goto END;
}

printf(" Formula: %s\n", cvalue);
printf("\n");

/* Read in size of the data matrix and number of variable labels supplied */
scanf("%" NAG_IFMT "%" NAG_IFMT "%" NAG_IFMT "%*[^\n] ", &nobs, &nvar,
&lvnames);

/* Allocate memory */
if (!(levels = NAG_ALLOC(nvar, Integer)) ||
!(vnames = NAG_ALLOC(lvnames, char *))) {
printf("Allocation failure\n");
exit_status = -1;
goto END;
}
for (i = 0; i < lvnames; i++)
if (!(vnames[i] = NAG_ALLOC(MAX_VNAME_LEN, char))) {
printf("Allocation failure\n");
exit_status = -1;
goto END;
}

/* Read in number of levels and names for the variables */
for (i = 0; i < nvar; i++) {
scanf("%" NAG_IFMT "", &levels[i]);
}
scanf("%*[^\n] ");

if (lvnames > 0) {
for (i = 0; i < lvnames; i++)
scanf("%50s", vnames[i]);
scanf("%*[^\n] ");
}

/* Call nag_blgm_lm_describe_data (g22ybc) to get a description of */
/* the data matrix */
nag_blgm_lm_describe_data(&hddesc,nobs,nvar,levels,lvnames,vnames,&fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_blgm_lm_describe_data (g22ybc).\n%s\n",
fail.message);
exit_status = 1;
goto END;
}

/* Read in the data matrix and response variable */
lddat = nobs;
sddat = nvar;
if (!(dat = NAG_ALLOC(lddat*sddat, double)) ||
!(y = NAG_ALLOC(nobs, double))) {
printf("Allocation failure\n");
exit_status = -1;
goto END;
}
for (i = 0; i < nobs; i++) {
for (j = 0; j < nvar; j++)
scanf("%lf", &DAT(i, j));
scanf("%lf", &y[i]);
}
scanf("%*[^\n] ");

/* Call nag_blgm_optset (g22zmc) to set optional arguments */
/* Want the design matrix in include an explicit term for the mean effect */
nag_blgm_optset(hform,"Explicit Mean = Yes",&fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_blgm_optset (g22zmc).\n%s\n", fail.message);
exit_status = 1;
goto END;
}

/* Call nag_blgm_lm_design_matrix (g22ycc) to get the size of */
/* the design matrix */
ldx = 0;
sdx = 0;
nag_blgm_lm_design_matrix(hform,hddesc,dat,lddat,sddat,&hxdesc,
x,ldx,sdx,&mx,&fail);
if (fail.code != NW_ARRAY_SIZE && fail.code != NW_ALTERNATIVE) {
printf("Error from nag_blgm_lm_design_matrix (g22ycc).\n%s\n",
fail.message);
exit_status = 1;
goto END;
}

/* Allocate design matrix */
ldx = nobs;
sdx = mx;
if (!(x = NAG_ALLOC(ldx*sdx, double))) {
printf("Allocation failure\n");
exit_status = -1;
goto END;
}

/* Call nag_blgm_lm_design_matrix (g22ycc) to generate the design matrix */
nag_blgm_lm_design_matrix(hform,hddesc,dat,lddat,sddat,&hxdesc,
x,ldx,sdx,&mx,&fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_blgm_lm_design_matrix (g22ycc).\n%s\n",
fail.message);
exit_status = 1;
goto END;
}

/* Display the design matrix */
printf(" Design Matrix (X)\n");
for (i = 0; i < nobs; i++) {
for (j = 0; j < mx; j++)
printf(" %4.1f",X(i,j));
printf("\n");
}

END:
/* Call nag_blgm_handle_free (g22zac) to clean-up the g22 handles */
nag_blgm_handle_free(&hform,&fail);
nag_blgm_handle_free(&hddesc,&fail);
nag_blgm_handle_free(&hxdesc,&fail);

NAG_FREE(dat);
NAG_FREE(x);
NAG_FREE(y);
NAG_FREE(levels);
for (i = 0; i < lvnames; i++)
NAG_FREE(vnames[i]);
NAG_FREE(vnames);
return (exit_status);
}

/* Read in a line from stdin and remove any comments */
char *pch;

/* Read in the model formula */
if (fgets(formula,nchar,stdin)) {
/* Strip comments from formula */
pch = strstr(formula,"::");
if (pch) *pch = '\0';
return formula;
} else {
return 0;
}
}
```
{"ft_lang_label":"__label__en","ft_lang_prob":0.53160024,"math_prob":0.9743234,"size":5108,"snap":"2021-31-2021-39","text_gpt3_token_len":1644,"char_repetition_ratio":0.13264106,"word_repetition_ratio":0.19568345,"special_character_ratio":0.35787,"punctuation_ratio":0.25538793,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99218166,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-28T13:27:40Z\",\"WARC-Record-ID\":\"<urn:uuid:c10311d2-4599-4b02-9cb1-7d3415279cd2>\",\"Content-Length\":\"30117\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:0336fef0-b0a9-4430-be38-4be095717bef>\",\"WARC-Concurrent-To\":\"<urn:uuid:15ee4838-5419-404e-b0ab-a0d5b8a34118>\",\"WARC-IP-Address\":\"78.129.168.4\",\"WARC-Target-URI\":\"https://www.nag.com/numeric/nl/nagdoc_26.2/nagdoc_cl26.2/examples/source/g22yace.c.html\",\"WARC-Payload-Digest\":\"sha1:Z45Q5PMXN7ZHKR2HNAYUNONJOO4HGHOQ\",\"WARC-Block-Digest\":\"sha1:MCCFQOA35TLHXB236FS3AR425YR4D4H5\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780060803.2_warc_CC-MAIN-20210928122846-20210928152846-00400.warc.gz\"}"}