Probit avec R : Différence entre versions
De Wiki ODR
| Ligne 1 : | Ligne 1 : | ||
| − | <pre><center>''' | + | <pre><? |
| + | |||
| + | // probit sous R | ||
| + | // Connexion BD test | ||
| + | //http://localhost/test_probit_cedric.php | ||
| + | |||
| + | $t = time() ; | ||
| + | |||
| + | echo "lancement du traitement : probit sous R<br><br>" ; | ||
| + | flush(); | ||
| + | |||
| + | echo " Ouverture en lecture du fichier de commande R<BR><BR>"; | ||
| + | flush(); | ||
| + | |||
| + | if ( !($fichier_R = fopen ('probit2.par', 'r'))) | ||
| + | { | ||
| + | print("impossible d'ouvrir le fichier probit2.par"); | ||
| + | exit; | ||
| + | } | ||
| + | |||
| + | |||
| + | fclose ($fichier_R); | ||
| + | |||
| + | $mysqldata = "c:\\easyphp\\mysql\\data\\$base\\"; | ||
| + | |||
| + | echo "traitement sous r (long) <BR><BR>" ; | ||
| + | flush(); | ||
| + | |||
| + | // exécution de R | ||
| + | $ATraiter = "c:\\rw2001\\bin\\Rterm.exe -q --no-restore --no-save < " . "probit2.par" . ">". "fichier_sortie"; | ||
| + | exec ($ATraiter); | ||
| + | |||
| + | // affichage | ||
| + | echo "Impression des resultats dans un tableau <BR><BR>" ; | ||
| + | flush(); | ||
| + | |||
| + | if ( !($fic_sortie = fopen ('C:\\Documents and Settings\\cedric\\Bureau\\probitessai.txt', 'r'))) | ||
| + | { | ||
| + | print("impossible d'ouvrir le fichier fichier_sortie"); | ||
| + | exit; | ||
| + | } | ||
| + | |||
| + | while (!feof($fic_sortie)) | ||
| + | { | ||
| + | $ligne = fgets ($fic_sortie, 500); | ||
| + | $ligne = trim($ligne) ; | ||
| + | if($ligne == '' ) continue ; | ||
| + | $ligne = explode(";" ,$ligne); | ||
| + | $var[] = $ligne[0] ; | ||
| + | $estim[] = $ligne[1] ; | ||
| + | $stderror[] = $ligne[2]; | ||
| + | $zvalue[] = $ligne[3]; | ||
| + | $prz[] = $ligne[4]; | ||
| + | } | ||
| + | |||
| + | // entête du tableaux | ||
| + | echo "<TABLE border=0 cellspacing='0' cellpading='5' >"; | ||
| + | echo "<tr BGCOLOR = #009900><TD colspan='11'></TD></TR>"; | ||
| + | echo "<TR bgcolor = #EAFCEA align='center'><TD BGCOLOR = #009900 width = '0px' ></TD><TD></TD><TD BGCOLOR = #009900 ></TD><TD >Estimate</TD> <TD BGCOLOR = #009900 width = '0px' ></TD> <TD>Std. Error</TD><TD BGCOLOR = #009900 width = '0px' ></TD><TD>z value</TD><TD BGCOLOR = #009900 ></TD><TD>Pr(>|z|)</TD><TD BGCOLOR = #009900 width = '0px' ></TD></TR>"; | ||
| + | echo "<tr BGCOLOR = #009900 width = '0px' ><TD colspan='11'></TD></TR>"; | ||
| + | |||
| + | // lignes du tableau | ||
| + | $i = 0 ; | ||
| + | while ( $i < count($var) ) | ||
| + | { | ||
| + | |||
| + | echo "<TR><TD BGCOLOR = #009900 ></TD><TD>".$var[$i]."</TD>"; | ||
| + | echo "<TD BGCOLOR = #009900 ></TD><TD Align = 'right' width = '20%' >".sprintf( "%.7f",$estim[$i])."</TD>"; | ||
| + | echo "<TD BGCOLOR = #009900 ></TD><TD Align = 'right' width = '20%' >".sprintf( "%.7f",$stderror[$i])."</TD>"; | ||
| + | echo "<TD BGCOLOR = #009900 ></TD><TD Align = 'right' width = '20%' >".sprintf( "%.2f",$zvalue[$i])."</TD>"; | ||
| + | echo "<TD BGCOLOR = #009900 ></TD><TD Align = 'right' width = '20%' >".sprintf( "%.3f",$prz[$i])."</TD>"; | ||
| + | echo "<TD BGCOLOR = #009900></TD></TR>" ; | ||
| + | $i++; | ||
| + | } | ||
| + | |||
| + | // cloture du tableau | ||
| + | echo "<tr BGCOLOR = #009900><TD colspan='11'></TD></TR>"; | ||
| + | echo"</TABLE>"; | ||
| + | |||
| + | $t1 = time() ; | ||
| + | $temps = $t1 - $t ; | ||
| + | echo "<BR> $temps secondes" ; | ||
| + | |||
| + | |||
| + | ?> | ||
| + | </pre> | ||
Version du 26 avril 2007 à 10:13
<?
// probit sous R
// Connexion BD test
//http://localhost/test_probit_cedric.php
$t = time() ;
echo "lancement du traitement : probit sous R<br><br>" ;
flush();
echo " Ouverture en lecture du fichier de commande R<BR><BR>";
flush();
if ( !($fichier_R = fopen ('probit2.par', 'r')))
{
print("impossible d'ouvrir le fichier probit2.par");
exit;
}
fclose ($fichier_R);
$mysqldata = "c:\\easyphp\\mysql\\data\\$base\\";
echo "traitement sous r (long) <BR><BR>" ;
flush();
// exécution de R
$ATraiter = "c:\\rw2001\\bin\\Rterm.exe -q --no-restore --no-save < " . "probit2.par" . ">". "fichier_sortie";
exec ($ATraiter);
// affichage
echo "Impression des resultats dans un tableau <BR><BR>" ;
flush();
if ( !($fic_sortie = fopen ('C:\\Documents and Settings\\cedric\\Bureau\\probitessai.txt', 'r')))
{
print("impossible d'ouvrir le fichier fichier_sortie");
exit;
}
while (!feof($fic_sortie))
{
$ligne = fgets ($fic_sortie, 500);
$ligne = trim($ligne) ;
if($ligne == '' ) continue ;
$ligne = explode(";" ,$ligne);
$var[] = $ligne[0] ;
$estim[] = $ligne[1] ;
$stderror[] = $ligne[2];
$zvalue[] = $ligne[3];
$prz[] = $ligne[4];
}
// entête du tableaux
echo "<TABLE border=0 cellspacing='0' cellpading='5' >";
echo "<tr BGCOLOR = #009900><TD colspan='11'></TD></TR>";
echo "<TR bgcolor = #EAFCEA align='center'><TD BGCOLOR = #009900 width = '0px' ></TD><TD></TD><TD BGCOLOR = #009900 ></TD><TD >Estimate</TD> <TD BGCOLOR = #009900 width = '0px' ></TD> <TD>Std. Error</TD><TD BGCOLOR = #009900 width = '0px' ></TD><TD>z value</TD><TD BGCOLOR = #009900 ></TD><TD>Pr(>|z|)</TD><TD BGCOLOR = #009900 width = '0px' ></TD></TR>";
echo "<tr BGCOLOR = #009900 width = '0px' ><TD colspan='11'></TD></TR>";
// lignes du tableau
$i = 0 ;
while ( $i < count($var) )
{
echo "<TR><TD BGCOLOR = #009900 ></TD><TD>".$var[$i]."</TD>";
echo "<TD BGCOLOR = #009900 ></TD><TD Align = 'right' width = '20%' >".sprintf( "%.7f",$estim[$i])."</TD>";
echo "<TD BGCOLOR = #009900 ></TD><TD Align = 'right' width = '20%' >".sprintf( "%.7f",$stderror[$i])."</TD>";
echo "<TD BGCOLOR = #009900 ></TD><TD Align = 'right' width = '20%' >".sprintf( "%.2f",$zvalue[$i])."</TD>";
echo "<TD BGCOLOR = #009900 ></TD><TD Align = 'right' width = '20%' >".sprintf( "%.3f",$prz[$i])."</TD>";
echo "<TD BGCOLOR = #009900></TD></TR>" ;
$i++;
}
// cloture du tableau
echo "<tr BGCOLOR = #009900><TD colspan='11'></TD></TR>";
echo"</TABLE>";
$t1 = time() ;
$temps = $t1 - $t ;
echo "<BR> $temps secondes" ;
?>

