; ;****************************************************** ; ; prototype and methods for inten-reg objects. ; ; ena - 3/7/2000. ; ;****************************************************** ; (provide "inten-reg-proto") ; (defproto inten-reg-proto '(freq inten covars covar-names has-rsq-plot rsq-plot has-pval-plot pval-plot has-coeff-plot coeff-plot)) ; (defmeth inten-reg-proto :calc-reg-vals () (let* ( (has-rsq-plot (send self :slot-value 'has-rsq-plot)) (has-pval-plot (send self :slot-value 'has-pval-plot)) (has-coeff-plot (send self :slot-value 'has-coeff-plot)) (inten (send self :slot-value 'inten)) (freq (send self :slot-value 'freq)) (covars (send self :slot-value 'covars)) (inten-sel (transpose (select inten *current-points*))) (covars-sel (transpose (select (transpose covars) *current-points*))) (reg (mapcar #'(lambda (x) (regression-model covars-sel x :print nil)) inten-sel)) (rsq (if (or has-rsq-plot has-pval-plot) (mapcar #'(lambda (x) (send x :r-squared)) reg) ) ) (f-pvals (if has-pval-plot (let* ( (n (send (first reg) :num-cases)) (k (- (send (first reg) :num-coefs) 1)) (dfden (- (- n k) 1)) (f (/ (* (/ rsq (- 1 rsq)) dfden) k)) ) (mapcar #'(lambda (x) (f-to-p x k dfden)) f) ) ) ) (coeff-vals (if (which has-coeff-plot) (let* ( (tdf (- (send (first reg) :num-cases) 1)) (tval (t-quant 0.975 tdf)) (coeff (mapcar #'(lambda (x) (send x :coef-estimates)) reg)) (se (mapcar #'(lambda (x) (send x :coef-standard-errors)) reg)) (marg (* tval se)) (low (- coeff marg)) (high (+ coeff marg)) ) (list (transpose coeff) (transpose low) (transpose high) ) ) ) ) ) (list (first freq) rsq f-pvals coeff-vals) ) ) ; (defmeth inten-reg-proto :install-plots () (let* ( (plot-info (get-plot-reg-info self)) (plot-rsq (first plot-info)) (plot-pval (second plot-info)) (plot-coeff (third plot-info)) (has-coeff-plot (send self :slot-value 'has-coeff-plot)) (coeff-plot (send self :slot-value 'coeff-plot)) (reg-vals nil) (plot-freq nil) (rsq nil) (pvals nil) ) (setf *current-points* (iseq (length (send self :slot-value 'inten)))) (if (and plot-rsq (send self :slot-value 'has-rsq-plot)) (send (send self :slot-value 'rsq-plot) :dispose) ) (if (and plot-pval (send self :slot-value 'has-pval-plot)) (send (send self :slot-value 'pval-plot) :dispose) ) (mapcar #'(lambda (x y z) (if (and x y) (send z :dispose))) plot-coeff has-coeff-plot coeff-plot) (if plot-rsq (send self :slot-value 'has-rsq-plot T)) (if plot-pval (send self :slot-value 'has-pval-plot T)) (setf has-coeff-plot (mapcar #'(lambda (x y) (or x y)) plot-coeff has-coeff-plot)) (if (which plot-coeff) (send self :slot-value 'has-coeff-plot has-coeff-plot) ) (setf reg-vals (send self :calc-reg-vals)) (setf plot-freq (first reg-vals)) (setf rsq (second reg-vals)) (setf pvals (third reg-vals)) ; (if plot-rsq ; (prog* ; ((plot (plot-lines plot-freq rsq :title "r-squared"))) ; (send plot :range 1 0 1) ; (send self :slot-value 'rsq-plot plot) ; ) ; ) ; (if plot-pval ; (prog* ; ( ; (plot (plot-lines plot-freq pvals ; :title "P value for regression")) ; ) ; (send plot :range 1 0 1) ; (send self :slot-value 'pval-plot plot) ; ) ; ) (if plot-rsq (install-rsq-pval-plot plot-freq rsq "r-squared" 'rsq-plot 'has-rsq-plot self) ) (if plot-pval (install-rsq-pval-plot plot-freq rsq "P value for regression" 'pval-plot 'has-pval-plot self) ) (if (which plot-coeff) (prog* ( (coeff-list (fourth reg-vals)) (coeff (first coeff-list)) (low (second coeff-list)) (high (third coeff-list)) (covar-names (append (list "constant") (send self :slot-value 'covar-names))) (plots (mapcar #'(lambda (flag coeff title low high var) (if flag (bld-inten-covars-plot plot-freq coeff low high title self var) ) ) plot-coeff coeff covar-names low high (iseq (length covar-names)) ) ) ) (setf coeff-plot (mapcar #'(lambda (x y z) (if x y z)) plot-coeff plots coeff-plot)) (send self :slot-value 'coeff-plot coeff-plot) ) ) ) ) ; (defmeth inten-reg-proto :draw-lines () (let* ( (plot-rsq (send self :slot-value 'has-rsq-plot)) (plot-pval (send self :slot-value 'has-pval-plot)) (has-coeff-plot (send self :slot-value 'has-coeff-plot)) (reg-vals nil) (plot-freq nil) (rsq nil) (pvals nil) ) (setf reg-vals (send self :calc-reg-vals)) (setf plot-freq (first reg-vals)) (setf rsq (second reg-vals)) (setf pvals (third reg-vals)) (send self :clear) (if plot-rsq (send (send self :slot-value 'rsq-plot) :add-lines plot-freq rsq) ) (if plot-pval (send (send self :slot-value 'pval-plot) :add-lines plot-freq pvals) ) (if (which has-coeff-plot) (prog* ( (coeff-plot (send self :slot-value 'coeff-plot)) (coeff-list (fourth reg-vals)) (coeff (first coeff-list)) (low (second coeff-list)) (high (third coeff-list)) ) (mapcar #'(lambda (flag coeff low high plot) (if flag (prog* () (send plot :redraw) (send plot :add-lines plot-freq coeff) (send plot :add-lines plot-freq low) (send plot :add-lines plot-freq high) ) )) has-coeff-plot coeff low high coeff-plot ) ) ) ) ) ; (defmeth inten-reg-proto :clear () (let* ( (plot-rsq (send self :slot-value 'has-rsq-plot)) (plot-pval (send self :slot-value 'has-pval-plot)) (plot-coeff (send self :slot-value 'has-coeff-plot)) ) (if plot-rsq (send (send self :slot-value 'rsq-plot) :clear) ) (if plot-pval (send (send self :slot-value 'pval-plot) :clear) ) (if (which plot-coeff) (mapcar #'(lambda (x y) (if x (send y :clear))) plot-coeff (send self :slot-value 'coeff-plot) ) ) ) )