User Tools

Site Tools


neuroimagen:altdti

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
neuroimagen:altdti [2019/03/19 10:01]
osotolongo [Todas las redes]
neuroimagen:altdti [2020/08/04 10:58] (current)
Line 1411: Line 1411:
 > fdata <-read.csv("facehbi_data.csv", sep = ";", header=TRUE) > fdata <-read.csv("facehbi_data.csv", sep = ";", header=TRUE)
 > fapoe <-read.csv("facehbi_apoe_strats.csv", sep = ";", header=TRUE) > fapoe <-read.csv("facehbi_apoe_strats.csv", sep = ";", header=TRUE)
 +> okdata <- merge(fdata, fapoe, by = "Subject")
 +> okdata <- merge(okdata, fdti, by = "Subject")
 > write.csv(okdata, file="facehbi_dti_np.csv") > write.csv(okdata, file="facehbi_dti_np.csv")
 > source("get_lms.r") > source("get_lms.r")
Line 1459: Line 1461:
 facehbi_dti_np_models_all.txt facehbi_dti_np_models_all.txt
 </code> </code>
 +
 +**Nota:** Estos hay que revisarlos despacio pues puede haber alguna asosiacion con el SUVR que hayamos pasado por alto.
 +
 +Ahora el otro composite,
 +<code R>
 +> fdata <-read.csv("facehbi_data_mb.csv", sep = ";", header=TRUE)
 +> okdata <- merge(okdata, fdata, by = "Subject")
 +> okdata$zPPp = (okdata$PPp - mean(okdata$PPp, na.rm = TRUE))/sd(okdata$PPp, na.rm = TRUE)
 +> okdata$zPPi = (okdata$PPi - mean(okdata$PPi, na.rm = TRUE))/sd(okdata$PPi, na.rm = TRUE)
 +> okdata$zKDi = (okdata$KDi - mean(okdata$KDi, na.rm = TRUE))/sd(okdata$KDi, na.rm = TRUE)
 +> okdata$zKDp = (okdata$KDp - mean(okdata$KDp, na.rm = TRUE))/sd(okdata$KDp, na.rm = TRUE)
 +> mb <- data.frame(okdata$zPPp, okdata$zPPi, okdata$zKDp, okdata$zKDi)
 +> okdata$cs <- mbsc$scores
 +</code>
 +<code bash>
 +[osotolongo@detritus dti_model]$ cat npvars.names
 +cs
 +</code>
 +<code R>
 +> write.csv(okdata, file="facehbi_dti_np.csv")
 +> source("get_lms.r")
 +Read 1 item
 +Read 4 items
 +</code>
 +y lo hago estratificado tambien, (moviendo los outputs como antes)
 +<code R>
 +> okdata0 <- okdata[okdata$APOE == "0",]
 +> write.csv(okdata0, file="facehbi_dti_np.csv")
 +> source("get_lms.r")
 +Read 1 item
 +Read 4 items
 +> okdata1 <- okdata[okdata$APOE == "1",]
 +> write.csv(okdata1, file="facehbi_dti_np.csv")
 +> source("get_lms.r")
 +Read 1 item
 +Read 4 items
 +> okdata2 <- okdata[okdata$APOE == "2",]
 +> write.csv(okdata2, file="facehbi_dti_np.csv")
 +> source("get_lms.r")
 +Read 1 item
 +Read 4 items
 +</code>
 +y aqui si no hay nada de nada.
 +Voy a hacerme un script para sacar cuando R2 es mayor que //0.3// por poner un numero,
 +<code perl checkr2.pl>
 +#!/usr/bin/perl
 +
 +use strict;
 +use warnings;
 +use Data::Dump qw(dump);
 +
 +my $ifile = "facehbi_dti_np_models_all.txt";
 +my $thresh = 0.3;
 +my %model;
 +open IDF, "<$ifile" or die "No such file\n";
 +while (<IDF>){
 +        if (/-------/ && $model{"r2"}>0.3) {
 +                print $model{"ni_var"}.",".$model{np_var}."\nr2 = ".$model{"r2"}.", p-value = ".$model{"pvalue"}."\npv_".$model{"ni_var"}." = ".$model{"pv_ni"}.", pv_SUVR = ".$model{pv_suvr}." \n";
 +        };
 +        if (/^NP:.*/) {($model{"np_var"}, $model{"ni_var"}) = /^NP:\s+(\w+)\s+NI:\s+(\w+)\s*$/};
 +        if (/^R2:.*/) {($model{"r2"}, $model{"pvalue"}) = /^R2:\s+(\S+)\s+p-value:\s+(\S+)/};
 +        if (/^p-value.*/) {($model{"pv_ni"}, $model{"pv_suvr"}) = /p-value.*:\s+(\S+)\s+p-value.*:\s+(\S+)/}
 +}
 +close IDF;
 +</code>
 +
 +Para todos,
 +
 +<code>
 +[osotolongo@detritus dti_model]$ ./checkr2.pl 
 +Analizing facehbi_dti_np_models_all.txt ...
 +
 +DMN_FA, funcioExecutiva_velocprocess_IM
 +r2 = 0.302226155665606, p-value = 1.59872115546023e-14
 +pv_DMN_FA = 0.883576950793585, pv_SUVR = 0.24424229051191 
 +
 +LN_FA, funcioExecutiva_velocprocess_IM
 +r2 = 0.302579788141454, p-value = 1.53210777398272e-14
 +pv_LN_FA = 0.731754149108559, pv_SUVR = 0.239811378742586 
 +
 +SN_FA, funcioExecutiva_velocprocess_IM
 +r2 = 0.302699583800708, p-value = 1.50990331349021e-14
 +pv_SN_FA = 0.698477685239432, pv_SUVR = 0.241344996365449 
 +
 +FPCustom_FA, funcioExecutiva_velocprocess_IM
 +r2 = 0.303857285316447, p-value = 1.28785870856518e-14
 +pv_FPCustom_FA = 0.495322950618766, pv_SUVR = 0.229845691710707 
 +</code>
 +
 +//APOE 0//
 +
 +<code>
 +[osotolongo@detritus dti_model]$ ./checkr2.pl 
 +Analizing facehbi_dti_np_models_0.txt ...
 +
 +DMN_FA, funcioExecutiva_velocprocess_IM
 +r2 = 0.379552223636583, p-value = 0.0057104958050207
 +pv_DMN_FA = 0.639790744923555, pv_SUVR = 0.0157173219667127 
 +
 +LN_FA, funcioExecutiva_velocprocess_IM
 +r2 = 0.373746758451691, p-value = 0.00627788677009611
 +pv_LN_FA = 0.922726301726418, pv_SUVR = 0.0179719566898906 
 +
 +SN_FA, funcioExecutiva_velocprocess_IM
 +r2 = 0.373504904382816, p-value = 0.00630256049240607
 +pv_SN_FA = 0.978604565669928, pv_SUVR = 0.0176943724392262 
 +
 +FPCustom_FA, funcioExecutiva_velocprocess_IM
 +r2 = 0.376679557258316, p-value = 0.00598535915763587
 +pv_FPCustom_FA = 0.734462972707933, pv_SUVR = 0.0164897973831555 
 +
 +DMN_FA, memoria_wms
 +r2 = 0.384900678414176, p-value = 0.00522814187347165
 +pv_DMN_FA = 0.971755525011924, pv_SUVR = 0.126202366929838 
 +
 +LN_FA, memoria_wms
 +r2 = 0.476189288707085, p-value = 0.000987730906959694
 +pv_LN_FA = 0.0571602758952463, pv_SUVR = 0.0786860000743259 
 +
 +SN_FA, memoria_wms
 +r2 = 0.4105573407532, p-value = 0.00337775223148928
 +pv_SN_FA = 0.327134537994976, pv_SUVR = 0.110122034640346 
 +
 +FPCustom_FA, memoria_wms
 +r2 = 0.38938771125582, p-value = 0.00485148460500173
 +pv_FPCustom_FA = 0.683663237630694, pv_SUVR = 0.141496294121895 
 +</code>
 +
 +//APOE 1// --> **nada**
 +
 +//APOE 2//
 +
 +<code>
 +[osotolongo@detritus dti_model]$ ./checkr2.pl 
 +Analizing facehbi_dti_np_models_2.txt ...
 +
 +DMN_FA, funcioExecutiva_velocprocess_IM
 +r2 = 0.485798156550142, p-value = 2.68765592381648e-06
 +pv_DMN_FA = 0.00443564461139048, pv_SUVR = 0.00250803493024018 
 +
 +LN_FA, funcioExecutiva_velocprocess_IM
 +r2 = 0.391142446695136, p-value = 7.40330891934038e-05
 +pv_LN_FA = 0.298247246087403, pv_SUVR = 0.00913580342963226 
 +
 +SN_FA, funcioExecutiva_velocprocess_IM
 +r2 = 0.473679765360014, p-value = 4.26313995949279e-06
 +pv_SN_FA = 0.0075840881661726, pv_SUVR = 0.00315334075632377 
 +
 +FPCustom_FA, funcioExecutiva_velocprocess_IM
 +r2 = 0.420481875101633, p-value = 2.83138960435192e-05
 +pv_FPCustom_FA = 0.0767718841930776, pv_SUVR = 0.00977255081753087 
 +
 +DMN_FA, memoria_fnameProf
 +r2 = 0.327588088792215, p-value = 0.000497956057757376
 +pv_DMN_FA = 0.773974302319369, pv_SUVR = 0.788744944522824 
 +
 +LN_FA, memoria_fnameProf
 +r2 = 0.382914152316493, p-value = 9.60047895888216e-05
 +pv_LN_FA = 0.0561917139565343, pv_SUVR = 0.624162892962772 
 +
 +SN_FA, memoria_fnameProf
 +r2 = 0.327676768593875, p-value = 0.000496710477748463
 +pv_SN_FA = 0.76680425794751, pv_SUVR = 0.789799021308529 
 +
 +FPCustom_FA, memoria_fnameProf
 +r2 = 0.331099185559454, p-value = 0.000450805039077462
 +pv_FPCustom_FA = 0.584035234528739, pv_SUVR = 0.810357038625016 
 +
 +DMN_FA, memoria_fnameNom
 +r2 = 0.328367049483929, p-value = 0.000487113972439834
 +pv_DMN_FA = 0.898296424312723, pv_SUVR = 0.0560073342550184 
 +
 +LN_FA, memoria_fnameNom
 +r2 = 0.330867944990235, p-value = 0.000453777260227328
 +pv_LN_FA = 0.679077371093828, pv_SUVR = 0.0600344325872235 
 +
 +SN_FA, memoria_fnameNom
 +r2 = 0.331778400581458, p-value = 0.000442179712075386
 +pv_SN_FA = 0.633252108652689, pv_SUVR = 0.0601087607629487 
 +
 +FPCustom_FA, memoria_fnameNom
 +r2 = 0.334618953643581, p-value = 0.000407752047013266
 +pv_FPCustom_FA = 0.524784142484717, pv_SUVR = 0.0519653979539324 
 +
 +DMN_FA, memoria_wms
 +r2 = 0.30272247894919, p-value = 0.000989109715828107
 +pv_DMN_FA = 0.228059068988977, pv_SUVR = 0.472409952167858 
 +
 +</code>
 +
 +Voy a mirar un poco,
 +
 +<code R>
 +> m0 <- lm(okdata0$funcioExecutiva_velocprocess_IM ~ okdata0$SUVR + okdata0$Edad)
 +> summary(m0)
 +
 +Call:
 +lm(formula = okdata0$funcioExecutiva_velocprocess_IM ~ okdata0$SUVR + 
 +    okdata0$Edad)
 +
 +Residuals:
 +    Min      1Q  Median      3Q     Max 
 +-1.3337 -0.5111 -0.1135  0.3141  2.5369 
 +
 +Coefficients:
 +             Estimate Std. Error t value Pr(>|t|)   
 +(Intercept)   2.79206    3.21204   0.869  0.39267   
 +okdata0$SUVR -6.70012    2.41598  -2.773  0.01013 * 
 +okdata0$Edad  0.07533    0.02137   3.526  0.00159 **
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +Residual standard error: 0.9002 on 26 degrees of freedom
 +Multiple R-squared:  0.4416, Adjusted R-squared:  0.3987 
 +F-statistic: 10.28 on 2 and 26 DF,  p-value: 0.0005129
 +
 +> m1 <- lm(okdata1$funcioExecutiva_velocprocess_IM ~ okdata1$SUVR + okdata1$Edad)
 +> summary(m1)
 +
 +Call:
 +lm(formula = okdata1$funcioExecutiva_velocprocess_IM ~ okdata1$SUVR + 
 +    okdata1$Edad)
 +
 +Residuals:
 +    Min      1Q  Median      3Q     Max 
 +-1.2138 -0.5730 -0.1959  0.2146  4.7844 
 +
 +Coefficients:
 +              Estimate Std. Error t value Pr(>|t|)    
 +(Intercept)  -4.200673   1.052358  -3.992 0.000114 ***
 +okdata1$SUVR  0.002109   0.780712   0.003 0.997849    
 +okdata1$Edad  0.063894   0.011991   5.328 4.82e-07 ***
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +Residual standard error: 0.8937 on 118 degrees of freedom
 +  (1 observation deleted due to missingness)
 +Multiple R-squared:  0.2052, Adjusted R-squared:  0.1918 
 +F-statistic: 15.24 on 2 and 118 DF,  p-value: 1.3e-06
 +
 +> m2 <- lm(okdata2$funcioExecutiva_velocprocess_IM ~ okdata2$SUVR + okdata2$Edad)
 +> summary(m2)
 +
 +Call:
 +lm(formula = okdata2$funcioExecutiva_velocprocess_IM ~ okdata2$SUVR + 
 +    okdata2$Edad)
 +
 +Residuals:
 +     Min       1Q   Median       3Q      Max 
 +-1.74708 -0.28264 -0.07348  0.26384  2.76441 
 +
 +Coefficients:
 +             Estimate Std. Error t value Pr(>|t|)    
 +(Intercept)  -4.49416    1.14875  -3.912   0.0003 ***
 +okdata2$SUVR  1.34940    0.54032   2.497   0.0161 *  
 +okdata2$Edad  0.04144    0.01738   2.384   0.0213 *  
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +Residual standard error: 0.8034 on 46 degrees of freedom
 +Multiple R-squared:  0.2749, Adjusted R-squared:  0.2434 
 +F-statistic: 8.719 on 2 and 46 DF,  p-value: 0.0006158
 +</code>
 +
 +
 +===== Riesgo - No riesgo =====
 +
 +Vamosaplantear el problema de manera distinta. Supongamos que la contribucion del APOE depende solo de la presencia del alelo $\epsilon$-4 y clasifiquemos los sujetos segun esto, en //con riesgo// o //sin riesgo//.
 +
 +<code R>
 +> okdata$Risk <- ifelse (okdata$APOE==2 , 1, 0)
 +</code>
 +
 +Pero ahora voy a hacer una cosa un poco mas complicada,
 +
 +<code R get_lms2.r>
 +library(QuantPsyc)
 +x<-read.csv("facehbi_dti_np.csv")
 +Color=c("red","blue")
 +scan("npvars.names", what = character())->np
 +scan("nivars.names", what = character())->ni
 +sink(file = "facehbi_dti_np_models.txt", append = TRUE, type = "output", split = FALSE)
 +
 +for(i in 1:length(np)){
 +        for(j in 1:length(ni)){
 +                y.data <- x[c(ni[j], np[i], "female", "Edad", "Escolaridad", "SUVR", "Risk")]
 +                y.data <- y.data[complete.cases(y.data),]
 +                a <- lm( paste ('y.data$', np[i], ' ~ y.data$', ni[j], ' + y.data$SUVR +y.data$Risk + y.data$female + y.data$Edad + y.data$Escolaridad + ', 'y.data$', ni[j], '*y.data$Risk'))
 +                writeLines(paste("NP: ", np[i], " NI: ", ni[j]))
 +                writeLines(paste("R2: ", summary(a)$adj.r.squared, " p-value: ", 1-pf(summary(a)$fstatistic[1], summary(a)$fstatistic[2], summary(a)$fstatistic[3])))
 +                writeLines(paste("p-value (", ni[j],"): ", summary(a)$coef[2,4], " p-value (SUVR): ", summary(a)$coef[3,4]))
 +                beta <- lm.beta(a)
 +                for(k in 1:length(beta)){
 +                        writeLines(paste(names(beta[k]), ": ", beta[k]))
 +                }
 +                writeLines(paste("-------"))
 +        }
 +}
 +sink()
 +</code>
 +
 +Asi que pruebo con el global,
 +
 +<code R>
 +> write.csv(okdata, file="facehbi_dti_np.csv")
 +> source("get_lms2.r")
 +</code>
 +
 +y luego,
 +
 +<code bash>
 +[osotolongo@detritus dti_model]$ ./checkr2.pl 
 +Analizing facehbi_dti_np_models.txt ...
 +
 +DMN_FA, funcioExecutiva_velocprocess_IM
 +r2 = 0.312799089824939, p-value = 2.93098878501041e-14
 +pv_DMN_FA = 0.476462254461098, pv_SUVR = 0.179281559330912 
 +
 +SN_FA, funcioExecutiva_velocprocess_IM
 +r2 = 0.311504329049638, p-value = 3.47499806707674e-14
 +pv_SN_FA = 0.551975051522526, pv_SUVR = 0.181998130409768 
 +
 +FPCustom_FA, funcioExecutiva_velocprocess_IM
 +r2 = 0.311678871879767, p-value = 3.39728245535298e-14
 +pv_FPCustom_FA = 0.151421806156447, pv_SUVR = 0.201473541858229 
 +</code>
 +
 +puaf, a ver,
 +
 +<code R>
 +> m <- lm(okdata$funcioExecutiva_velocprocess_IM ~ okdata$SUVR + okdata$Edad + okdata$Escolaridad + okdata$female + okdata$DMN_FA*okdata$Risk)
 +> summary(m)
 +
 +Call:
 +lm(formula = okdata$funcioExecutiva_velocprocess_IM ~ okdata$SUVR + 
 +    okdata$Edad + okdata$Escolaridad + okdata$female + okdata$DMN_FA * 
 +    okdata$Risk)
 +
 +Residuals:
 +    Min      1Q  Median      3Q     Max 
 +-1.4094 -0.5672 -0.1264  0.3442  4.3680 
 +
 +Coefficients:
 +                           Estimate Std. Error t value Pr(>|t|)    
 +(Intercept)                -4.12971    1.33068  -3.103  0.00221 ** 
 +okdata$SUVR                 0.58201    0.43176   1.348  0.17928    
 +okdata$Edad                 0.05310    0.00865   6.139 4.82e-09 ***
 +okdata$Escolaridad         -0.04301    0.01362  -3.157  0.00186 ** 
 +okdata$female              -0.38688    0.13066  -2.961  0.00346 ** 
 +okdata$DMN_FA               2.24716    3.14978   0.713  0.47646    
 +okdata$Risk                 5.03080    2.38260   2.111  0.03605 *  
 +okdata$DMN_FA:okdata$Risk -15.70430    7.30118  -2.151  0.03276 *  
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +Residual standard error: 0.8286 on 188 degrees of freedom
 +  (4 observations deleted due to missingness)
 +Multiple R-squared:  0.3375, Adjusted R-squared:  0.3128 
 +F-statistic: 13.68 on 7 and 188 DF,  p-value: 2.936e-14
 +</code>
 +
 +No, gracias. :-\
  
neuroimagen/altdti.1552989664.txt.gz · Last modified: 2020/08/04 10:46 (external edit)