Question

I have built this fairly simple program for use in my honors thesis (in psychcology) it basically models one way in which people think humans make decisions. I have actual human data that I am comparing to the results I am getting from this program to determine if this model is accurate. I have fairly limited programming experience but I need to be able to collect the standard deviation for the variables rtCorrect and rtIncorrect. I am guessing this will involve putting the numbers in an array.

I know you guys like to lead people to the correct answer instead of just giving it to them which is great but keep in mind this is not programming homework and I am not looking to become a programmer and I have a major thesis due this week! If any one could give me some pretty specific advice on doing this that would be so amazing, thanks!

By the way, you can ignore the commented out parts for now (unless you have a way for me to run that without it taking 2 months)!

EDIT: I need to find the variance/standard deviation for the variables RTcorrect and RTincorrect (i need to find the variance and standard deviation of each). I do not think my program currently saves these numbers so I am guessing I will need to put these numbers in an array to be analyzed after.

import java.util.Random;

public class Thesis4 {

    public static void main (String [] args){

        int totalRTIncorrect = 0;
        int totalRTCorrect = 0;
        int totalCorrect = 0;
        int totalIncorrect = 0;

        for (int j = 0; j < 10000;j++){
            int correct = 0;
            int incorrect = 0;
            int incorrect2 = 0;
            int incorrect3 =0;
            int rtCorrect = 0;
            int rtIncorrect = 0;
            int time = 0;

            while(correct<88 && incorrect<88){
                Random rand = new Random();
                int pickedNumber = rand.nextInt(400);

                if (pickedNumber<108){
                    correct++;
                    //incorrect--;
                    //incorrect2--;
                    //incorrect3--;
                    time++;

                }
                else if (pickedNumber>107 && pickedNumber<208){
                    incorrect++;
                    //  correct--;
                    //  incorrect2--;
                    //  incorrect3--;
                    time++;
                }
                else if (pickedNumber>207&&pickedNumber<309){
                    incorrect2++;
                    //  correct--;
                    //  incorrect--;
                    //  incorrect3--;
                    time++;
                }
                else if (pickedNumber>308){
                    incorrect3++;
                    //  correct--;
                    //  incorrect--;
                    //  incorrect2--;
                    time++;
                }
            }
            if (correct == 88){
                rtCorrect = time;
                totalCorrect++;
            }
            else if (incorrect == 88){
                rtIncorrect = time;
                totalIncorrect++;
            }
            else if (incorrect2 == 88){
                rtIncorrect = time;
                totalIncorrect++;
            }
            else if (incorrect3 == 88){
                rtIncorrect=time;
                totalIncorrect++;
            }

            totalRTIncorrect = totalRTIncorrect + rtIncorrect;
            totalRTCorrect = totalRTCorrect + rtCorrect;
        }
        System.out.printf ("Total Correct Responses: %d \nTotal Incorrect Responses: %d", totalCorrect, totalIncorrect);
        System.out.printf ("\nTotal Correct RT's: %d \nTotal Incorrect RT's: %d\n", totalRTCorrect, totalRTIncorrect);
    }
}
Was it helpful?

Solution

If you want to compute the standard deviation between the three variables "totalCorrect", "totalRTCorrect" and "totalRTIncorrect", the easiest way is to do it in four steps:

  • Step1: Get the average of the three variables, which is

    Mean= (totalCorrect+totalRTCorrect+totalRTIncorrect)/3.0
    
  • Step2: compute the values :

    a=(totalCorrect-Mean)*(totalCorrect-Mean)
    b=(totalRTCorrect-Mean)*(totalRTCorrect-Mean)
    c=(totalRTIncorrect-Mean)*(totalRTIncorrect-Mean)
    
  • Step3: Compute the mean of a,b, and c

    mean2= (a+b+c)/3.
    
  • Step4: take the square root of mean2.

    std=sqrt(mean2)
    

and that would be the standard deviation of the three variables . So, a new version of your code should look like this:

    import java.util.Random;
    import java.lang.Math;

    public class Thesis4 {

public static void main (String [] args){

    int totalRTIncorrect = 0;
    int totalRTCorrect = 0;
    int totalCorrect = 0;
    int totalIncorrect = 0;

    for (int j = 0; j < 10000;j++){
        int correct = 0;
        int incorrect = 0;
        int incorrect2 = 0;
        int incorrect3 =0;
        int rtCorrect = 0;
        int rtIncorrect = 0;
        int time = 0;

        while(correct<88 && incorrect<88){
            Random rand = new Random();
            int pickedNumber = rand.nextInt(400);

            if (pickedNumber<108){
                correct++;
                //incorrect--;
                //incorrect2--;
                //incorrect3--;
                time++;

            }
            else if (pickedNumber>107 && pickedNumber<208){
                incorrect++;
                //  correct--;
                //  incorrect2--;
                //  incorrect3--;
                time++;
            }
            else if (pickedNumber>207&&pickedNumber<309){
                incorrect2++;
                //  correct--;
                //  incorrect--;
                //  incorrect3--;
                time++;
            }
            else if (pickedNumber>308){
                incorrect3++;
                //  correct--;
                //  incorrect--;
                //  incorrect2--;
                time++;
            }
        }
        if (correct == 88){
            rtCorrect = time;
            totalCorrect++;
        }
        else if (incorrect == 88){
            rtIncorrect = time;
            totalIncorrect++;
        }
        else if (incorrect2 == 88){
            rtIncorrect = time;
            totalIncorrect++;
        }
        else if (incorrect3 == 88){
            rtIncorrect=time;
            totalIncorrect++;
        }

        totalRTIncorrect = totalRTIncorrect + rtIncorrect;
        totalRTCorrect = totalRTCorrect + rtCorrect;
    }
    System.out.printf ("Total Correct Responses: %d \nTotal Incorrect Responses: %d", totalCorrect, totalIncorrect);
    System.out.printf ("\nTotal Correct RT's: %d \nTotal Incorrect RT's: %d\n", totalRTCorrect, totalRTIncorrect);

    //computation of the standard deviation of the three variables
    double meanValue=(totalCorrect+totalRTCorrect+totalRTIncorrect)/3.0; //step1

    double a= (totalCorrect-meanValue)*(totalCorrect-meanValue);         //step2
    double b= (totalRTCorrect-meanValue)*(totalRTCorrect-meanValue);
    double c= (totalRTIncorrect-meanValue)*(totalRTIncorrect-meanValue);

    double mean2=(a+b+c)/3.0;                                          //step3

    double standard_deviation=Math.sqrt(mean2);                        //step4
    System.out.printf ("\nThe standard deviation of the three variables is %f\n",standard_deviation);

}
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top