/********************************************************************** * * fitqtl_hk.c * * copyright (c) 2007-2014, Karl W Broman * * last modified Mar, 2014 * first written Nov, 2007 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License, * version 3, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but without any warranty; without even the implied warranty of * merchantability or fitness for a particular purpose. See the GNU * General Public License, version 3, for more details. * * A copy of the GNU General Public License, version 3, is available * at http://www.r-project.org/Licenses/GPL-3 * * C functions for the R/qtl package * * These functions are for fitting a fixed multiple-QTL model by * Haley-Knott regression. * * Contains: R_fitqtl_hk, fitqtl_hk, galtRssHK * **********************************************************************/ #include #include #include #include #include #include #include #include #include "util.h" #include "fitqtl_hk.h" #include "fitqtl_imp.h" #define TOL 1e-12 void R_fitqtl_hk(int *n_ind, int *n_qtl, int *n_gen, double *genoprob, int *n_cov, double *cov, int *model, int *n_int, double *pheno, int *get_ests, /* return variables */ double *lod, int *df, double *ests, double *ests_covar, double *design_mat, int *matrix_rank, double *residuals) { double ***Genoprob=0, **Cov=0; int tot_gen, i, j, curpos; /* reorganize genotype probabilities */ if(*n_qtl > 0) { Genoprob = (double ***)R_alloc(*n_qtl, sizeof(double **)); tot_gen = 0; for(i=0; i < *n_qtl; i++) tot_gen += (n_gen[i]+1); Genoprob[0] = (double **)R_alloc(tot_gen, sizeof(double *)); for(i=1; i < *n_qtl; i++) Genoprob[i] = Genoprob[i-1] + (n_gen[i-1]+1); for(i=0, curpos=0; i < *n_qtl; i++) for(j=0; j 0) idx_int_q = (int *)R_alloc(n_qtl, sizeof(int)); X = (double **)R_alloc(sizefull, sizeof(double *)); /* split the memory block: design matrix x will be (n_ind x sizefull), coef will be (1 x sizefull), qty will be (1 x n_ind), qraux will be (1 x sizefull), work will be (2 x sizefull) */ X[0] = dwork; for(i=1; i 0; 2 -> 1. For F2, genotype 1 -> [0 0]; 2 -> [1 0]; 3 ->[0 1]. For 4-way, 1 -> [0 0 0], 2 -> [1 0 0], 3 -> [0 1 0], 4 -> [0 0 1] and so on */ for(i=0; i=0; k--) { /* go through QTL involved in this interaction */ thisidx = idx_int_q[k]; totrep = n_int_col / (n_gen[thisidx] * nrep); thecol = 0; for(outerrep=0; outerrep < totrep; outerrep++) { for(gen=0; gen