Monthly Archives: November 2015

Simple Regression in R

In this post, we will look at how to perform a simple regression using R. We will use a built-in dataset in R called ‘mtcars.’ There are several variables in this dataset but we will only use ‘wt’ which stands for the weight of the cars and ‘mpg’ which stands for miles per gallon.

Developing the Model

We want to know the association or relationship between the weight of a car and miles per gallon. We want to see how much of the variance of ‘mpg’ is explained by ‘wt’. Below is the code for this.

> Carmodel <- lm(mpg ~ wt, data = mtcars)

Here is what we did

  1. We created the variable ‘Carmodel’ to store are information
  2. Inside this variable, we used the ‘lm’ function to tell R to make a linear model.
  3. Inside the function, we put ‘mpg ~ wt’ the ‘~’ sign means ’tilda’ in English and is used to indicate that ‘mpg’ is a function of ‘wt’. This section is the actual notation for the regression model.
  4. After the comma, we see ‘data = mtcars’ this is telling R to use the ‘mtcar’ dataset.

Seeing the Results

Once you pressed enter you probably noticed nothing happens. The model ‘Carmodel’ was created but the results have not been displayed. Below is various information you can extract from your model.

The ‘summary’ function is useful for pulling most of the critical information. Below is the code for the output.

> summary(Carmodel)

Call:
lm(formula = mpg ~ wt, data = mtcars)

Residuals:
    Min      1Q  Median      3Q     Max 
-4.5432 -2.3647 -0.1252  1.4096  6.8727 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  37.2851     1.8776  19.858  < 2e-16 ***
wt           -5.3445     0.5591  -9.559 1.29e-10 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 3.046 on 30 degrees of freedom
Multiple R-squared:  0.7528,	Adjusted R-squared:  0.7446 
F-statistic: 91.38 on 1 and 30 DF,  p-value: 1.294e-10

We are not going to explain the details of the output (please see simple regression). The results indicate a model that explains 75% of the variance or has an r-square of 0.75. The model is statistically significant and the equation of the model is -5.45x + 37.28 = y

Plotting the Model

We can also plot the model using the code below

> coef_Carmodel<-coef(Carmodel)
> plot(mpg ~ wt, data = mtcars)
> abline(a = coef_Carmodel[1], b = coef_Carmodel[2])

Here is what we did

  1. We made the variable ‘coef_Carmodel’ and stored the coefficients (intercept and slope) of the ‘Carmodel’ using the ‘coef’ function. We will need this information soon.
  2. Next, we plot the ‘mtcars’ dataset using ‘mpg’ and ‘wt’.
  3. To add the regression line we use the ‘abline’ function. To add the intercept and slope we use a = the intercept from our ‘coef_Carmodel’ variable which is subset [1] from this variable. For slope, we follow the same process but use a [2]. This will add the line and your graph should look like the following.

Rplot10

From the visual, you can see that as weight increases there is a decrease in miles per gallon.

Conclusion

R is capable of much more complex models than the simple regression used here. However, understanding the coding for simple modeling can help in preparing you for much more complex forms of statistical modeling.

Levels of Reading Comprehension

Reading comprehension is a key academic skill. To comprehend a reading text means to understand what the author was trying to communicate and to share the author’s intentions along with, if possible, your own perspective on the text. Doing this is not easy at all.

In general, there are three levels of reading comprehension and they are.

  1. Decoding
  2. Critical literacy
  3. Dynamic literacy

This post will discuss each of these three levels of reading comprehension.

Decoding

Decoding is the most basic level of reading comprehension. At this level, a person breaking down words into there component syllables and “sounding them out.” He or she blends the words together and reads the text. This is the experience of many people who are learning to read. The focus is on learning to read and not reading to learn.

There is a minimal amount of reading comprehension at this level. The reader can recall what they read based on memory but there is often an inability to think and comprehend at a deeper level beyond memory.

For teaching, teaching decoding normal happens either with ESL students or with native speakers in early the early primary grades. This can be taught using a phonics-based approach, whole reading approach or some other method.

Critical Literacy

Critical literacy assumes that decoding has already happened. At this level, the reader is actively trying to develop a deeper understanding of the text. This happens through analyzing, comparing, contrasting, synthesizing, and or evaluating. The reader is engaged in a dialog with the text in trying to understand it.

Developing critical literacy in students requires employing teaching and learning strategies from the higher levels of Bloom’s Taxonomy. Leading discussions that require higher level thinking and or writing assignments are some ways to accomplish this.

It is important to remember that readers should have already mastered decoding before attempting critical literacy. It is easy to cause cognitive overload by trying to have a reader decode text while trying to discuss the deeper meaning of the content. As such, critical literacy strategies should be avoided until upper primary school.

Dynamic Literacy

Dynamic literacy assumes mastery of decoding and some mastery of critical literacy. Dynamic literacy goes beyond analysis to relate the content of the text to other knowledge. If critical literacy is focused only on the text, dynamic literacy is focused on how the current text of the reading relates to other books.

For example, a reader who is reading a book about language acquisition may look for connections between the acquisition of a language and grammar. Or they may be more creative and look for connections between language acquisition and music. This interdisciplinary focus is unique to what is currently considered the highest level of reading comprehension.

A more practical approach to doing this would be to compare what several authors say about the same subject. Again, the focus is on going beyond just one book or one subject to going across different books and or viewpoints. In general, dynamic literacy is probably not possible before high school or even college.

Conclusion

Many people never move beyond decoding. They are content with reading a text and knowing what happens but never thinking deeper beyond that. However, for some, higher levels of reading comprehension is not a goal. For many, reading the newspaper in English is all they want to do and they have no desire for a more complex reading experience.  The challenge for a teacher is to move readers from one level to the next while keeping in mind the goals of the students

Experimental Design: Within Groups

Within groups, experimental design is the use of only one group in an experiment. This is in contrast to a between-group design which involves two or more groups. Within-group design is useful when the number of is two low in order to split them into different groups.

There are two common forms of within-group experimental design, time-series, and repeated measures. Under time series there are interrupted times series and equivalent time series. Under repeated-measure, there is only repeated measure design. In this post, we will look at the following forms of within-group experimental design.

  • interrupted time series
  • equivalent time series
  • repeated measures design

Interrupted Time Series Design

Interrupted time series design involves several pre-tests followed by an intervention and then several post-test of one group. By measuring the several times, many threats to internal validity are reduced, such as regression, maturation, and selection. The pre-test results are also used as covariates when analyzing the post-tests.

Equivalent Time Series Design

Equivalent time series design involves the use of a measurement followed by intervention followed by measurement etc. In many ways, this design is a repeated post-test only design. The primary goal is to plot the results of the post-test and determine if there is a pattern that develops over time.

For example, if you are tracking the influence of blog writing on vocabulary acquisition, the intervention is blog writing and the dependent variable is vocabulary acquisition. As the students write a blog, you measure them several times over a certain period. If a plot indicates an upward trend you could infer that blog writing made a difference in vocabulary acquisition.

Repeated Measures

Repeated measures is the use of several different treatments over time. Before each treatment, the group is measured. Each post-test is compared to other post-test to determine which treatment was the best.

For example, let’s say that you still want to assess vocabulary acquisition but want to see how blog writing and public speaking affect it. First, you measure vocabulary acquisition. Next, you employ the first intervention followed by a second assessment of vocabulary acquisition. Third, you use the public speaking intervention followed by the third assessment of vocabulary acquisition. You now have three parts of data to compare

  1. The first assessment of vocabulary acquisition (a pre-test)
  2. The second assessment of vocabulary acquisition (post-test 1 after the blog writing)
  3. The third assessment of vocabulary acquisition (post-test 2 after the public speaking)

Conclusion

Within-group experimental designs are used when it is not possible to have several groups in an experiment. The benefits include needing fewer participants. However, one problem with this approach is the need to measure several times which can be labor intensive.

ANOVA with R

Analysis of variance (ANOVA) is used when you want to see if there is a difference in the means of three or more groups due to some form of treatment(s). In this post, we will look at conducting an ANOVA calculation using R.

We are going to use a dataset that is already built into R called ‘InsectSprays.’ This dataset contains information on different insecticides and their ability to kill insects. What we want to know is which insecticide was the best at killing insects.

In the dataset ‘InsectSprays’, there are two variables, ‘count’, which is the number of dead bugs, and ‘spray’ which is the spray that was used to kill the bug. For the ‘spray’ variable there are six types label A-F. There are 72 total observations for the six types of spray which comes to about 12 observations per spray.

Building the Model

The code for calculating the ANOVA is below

> BugModel<- aov(count ~ spray, data=InsectSprays)
> BugModel
Call:
   aov(formula = count ~ spray, data = InsectSprays)

Terms:
                   spray Residuals
Sum of Squares  2668.833  1015.167
Deg. of Freedom        5        66

Residual standard error: 3.921902
Estimated effects may be unbalanced

Here is what we did

  1. We created the variable ‘BugModel’
  2. In this variable, we used the function ‘aov’ which is the ANOVA function.
  3. Within the ‘aov’ function we told are to determine the count by the difference sprays that is what the ‘~’ tilde operator does.
  4. After the comma, we told R what dataset to use which was “InsectSprays.”
  5. Next, we pressed ‘enter’ and nothing happens. This is because we have to make R print the results by typing the name of the variable “BugModel” and pressing ‘enter’.
  6. The results do not tell us anything too useful yet. However, now that we have the ‘BugModel’ saved we can use this information to find the what we want.

Now we need to see if there are any significant results. To do this we will use the ‘summary’ function as shown in the script below

> summary(BugModel)
            Df Sum Sq Mean Sq F value Pr(>F)    
spray        5   2669   533.8    34.7 <2e-16 ***
Residuals   66   1015    15.4                   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

These results indicate that there are significant results in the model as shown by the p-value being essentially zero (Pr(>F)). In other words, there is at least one mean that is different from the other means statistically.

We need to see what the means are overall for all sprays and for each spray individually. This is done with the following script

> model.tables(BugModel, type = 'means')
Tables of means
Grand mean
    
9.5 

 spray 
spray
     A      B      C      D      E      F 
14.500 15.333  2.083  4.917  3.500 16.667

The ‘model.tables’ function tells us the means overall and for each spray. As you can see, it appears spray F is the most efficient at killing bugs with a mean of 16.667.

However, this table does not indicate the statistically significance. For this we need to conduct a post-hoc Tukey test. This test will determine which mean is significantly different from the others. Below is the script

> BugSpraydiff<- TukeyHSD(BugModel)
> BugSpraydiff
  Tukey multiple comparisons of means
    95% family-wise confidence level

Fit: aov(formula = count ~ spray, data = InsectSprays)

$spray
           diff        lwr       upr     p adj
B-A   0.8333333  -3.866075  5.532742 0.9951810
C-A -12.4166667 -17.116075 -7.717258 0.0000000
D-A  -9.5833333 -14.282742 -4.883925 0.0000014
E-A -11.0000000 -15.699409 -6.300591 0.0000000
F-A   2.1666667  -2.532742  6.866075 0.7542147
C-B -13.2500000 -17.949409 -8.550591 0.0000000
D-B -10.4166667 -15.116075 -5.717258 0.0000002
E-B -11.8333333 -16.532742 -7.133925 0.0000000
F-B   1.3333333  -3.366075  6.032742 0.9603075
D-C   2.8333333  -1.866075  7.532742 0.4920707
E-C   1.4166667  -3.282742  6.116075 0.9488669
F-C  14.5833333   9.883925 19.282742 0.0000000
E-D  -1.4166667  -6.116075  3.282742 0.9488669
F-D  11.7500000   7.050591 16.449409 0.0000000
F-E  13.1666667   8.467258 17.866075 0.0000000

There is a lot of information here. To make things easy, wherever there is a p adj of less than 0.05 that means that there is a difference between those two means. For example, bug spray F and E have a difference of 13.16 that has a p adj of zero. So these two means are really different statistically.This chart also includes the lower and upper bounds of the confidence interval.

The results can also be plotted with the script below

> plot(BugSpraydiff, las=1)

Below is the plot

Rplot10

Conclusion

ANOVA is used to calculate if there is a difference of means among three or more groups. This analysis can be conducted in R using various scripts and codes.

Qualitative Research: Hermeneutics & Phenomenology

Key components of qualitative research include hermeneutics and phenomenology. This post will examine these two terms and their role in qualitative research.

Hermeneutics

Hermeneutics is essential a method of interpretation of a text. The word hermeneutics comes from Hermes, the Greek messenger God. As such, at least for the ancient Greeks, there was a connection with interpreting and serving as a messenger. Today, his term is most commonly associated with theology such as biblical hermeneutics.

In relation to biblical hermeneutics, Augustine (354-430) develop a process of hermeneutics that was iterative. Through studying the Bible and the meaning of one’s own interpretations of the Bible, a person can understand divine truth. There was no need to look at the context, history, or anything else. Simply the Word and your interpretation of it.

In the 17th century, the Dutch philosopher Spinoza expanded on Augustine’s view of hermeneutics by stating that the text, its historical context, and even the author of a text, should be studied to understand the text. In other words, text plus context leads to truth.

By combing Augustine’s view of the role of the individual in hermeneutics with Spinoza’s contribution to the context we arrive at how interpretation happens in qualitative research.

In qualitative research, data interpretation (aka hermeneutics) involves the individual’s interpretation combined with the context that the data comes from. Both the personal interpretation and the context of the data influence each other.

Phenomenology

The develops in hermeneutics led to the development of the philosophy called phenomenology. Phenomenology states that a phenomenon can only be understood subjectively (from a certain viewpoint) and intuitively (through thinking and finding hidden meaning).

In phenomenology, interpretation happens through describing events, analyzing an event, and by connecting a current experience to another one or by finding similarities among distinct experiences.

For a phenomenologist, there is a constant work of reducing several experiences into abstract constructs through an inductive approach. This is a form of theory building that is connected with several forms of qualitative research, such as grounded theory.

Conclusion

Hermeneutics has played an important role in qualitative research by influencing the development of phenomenology. The study of a phenomenon is for the purpose of seeing how context will influence interpretation.

Experimental Designs: Between Groups

In experimental research, there are two common designs. They are between and within group design. The difference between these two groups of designs is that between group involves two or more groups in an experiment while within group involves only one group.

This post will focus on between group designs. We will look at the following forms of between group design…

  • True/quasi-experiment
  • Factorial Design

True/quasi Experiment

A true experiment is one in which the participants are randomly assigned to different groups. In a quasi-experiment, the researcher is not able to randomly assigned participants to different groups.

Random assignment is important in reducing many threats to internal validity. However, there are times when a researcher does not have control over this, such as when they conduct an experiment at a school where classes have already been established. In general, a true experiment is always considered superior methodological to a quasi-experiment.

Whether the experiment is a true experiment or a quasi-experiment. There are always two groups that are compared in the study. One group is the controlled group, which does not receive the treatment. The other group is called the experimental group, which receives the treatment of the study. It is possible to have more than two groups and several treatments but the minimum for between group designs is two groups.

Another characteristic that true and quasi-experiments have in common is the type of formats that the experiment can take. There are two common formats

  • Pre- and post test
  • Post test only

A pre- and post test involves measuring the groups of the study before the treatment and after the treatment. The desire normally is for the groups to be the same before the treatment and for them to be different statistically after the treatment. The reason for them being different is because of the treatment, at least hopefully.

For example, let’s say you have some bushes and you want to see if the fertilizer you bought makes any difference in the growth of the bushes.  You divide the bushes into two groups, one that receives the fertilizer (experimental group), and one that does not (controlled group). You measure the height of the bushes before the experiment to be sure they are the same. Then, you apply the fertilizer to the experimental group and after a period of time, you measure the heights of both groups again. If the fertilized bushes grow taller than the control group you can infer that it is because of the fertilizer.

Post-test only design is when the groups are measured only after the treatment. For example, let’s say you have some corn plants and you want to see if the fertilizer you bought makes any difference.in the amount of corn produced.  You divide the corn plants into two groups, one that receives the fertilizer (experimental group), and one that does not (controlled group). You apply the fertilizer to the control group and after a period of time, you measure the amount of corn produced. If the fertilized corn produces more you can infer that it is because of the fertilizer. You never measure the corn beforehand because they had not produced any corn yet.

Factorial design involves the use of more than one treatment. Returning to the corn example, let’s say you want to see not only how fertilizer affects corn production but also how the amount of water the corn receives affects production as well.

In this example, you are trying to see if there is an interaction effect between fertilizer and water.  When water and fertilizer are increased does production increase, is there no increase, or if one goes up and the other goes down does that have an effect?

Conclusion

Between group designs such as true and quasi-experiments provide a way for researchers to establish cause and effect. Pre- post test is employed as well as factorial designs to establish relationships between variables

Calculating Chi-Square in R

There are times when conducting research that you want to know if there is a difference in categorical data. For example, is there a difference in the number of men who have blue eyes and who have brown eyes. Or is there a relationship between gender and hair color. In other words, is there a difference in the count of a particular characteristic or is there a relationship between two or more categorical variables.

In statistics, the chi-square test is used to compare categorical data. In this post, we will look at how you can use the chi-square test in R.

For our example, we are going to use data that is already available in R called “HairEyeColor”. Below is the data

> HairEyeColor
, , Sex = Male

       Eye
Hair    Brown Blue Hazel Green
  Black    32   11    10     3
  Brown    53   50    25    15
  Red      10   10     7     7
  Blond     3   30     5     8

, , Sex = Female

       Eye
Hair    Brown Blue Hazel Green
  Black    36    9     5     2
  Brown    66   34    29    14
  Red      16    7     7     7
  Blond     4   64     5     8

As you can see, the data comes in the form of a list and shows hair and eye color for men and women in separate tables. The current data is unusable for us in terms of calculating differences. However, by using the ‘marign.table’ function we can make the data useable as shown in the example below.

> HairEyeNew<- margin.table(HairEyeColor, margin = c(1,2))
> HairEyeNew
       Eye
Hair    Brown Blue Hazel Green
  Black    68   20    15     5
  Brown   119   84    54    29
  Red      26   17    14    14
  Blond     7   94    10    16

Here is what we did. We created the variable ‘HairEyeNew’ and we stored the information from ‘HairEyeColor’ into one table using the ‘margin.table’ function. The margin was set 1,2 for the table.

Now all are data from the list are combined into one table.

We now want to see if there is a particular relationship between hair and eye color that is more common. To do this, we calculate the chi-square statistic as in the example below.

> chisq.test(HairEyeNew)

	Pearson's Chi-squared test

data:  HairEyeNew
X-squared = 138.29, df = 9, p-value < 2.2e-16

The test tells us that one or more of the relationships are more common than others within the table. To determine which relationship between hair and eye color is more common than the rest we will calculate the proportions for the table as seen below.

> HairEyeNew/sum(HairEyeNew)
       Eye
Hair          Brown        Blue       Hazel       Green
  Black 0.114864865 0.033783784 0.025337838 0.008445946
  Brown 0.201013514 0.141891892 0.091216216 0.048986486
  Red   0.043918919 0.028716216 0.023648649 0.023648649
  Blond 0.011824324 0.158783784 0.016891892 0.027027027

As you can see from the table, brown hair and brown eyes are the most common (0.20 or 20%) flowed by blond hair and blue eyes (0.15 or 15%).

Conclusion

The chi-square serves to determine differences among categorical data. This tool is useful for calculating the potential relationships among non-continuous variables

Philosophical Foundations of Research: Epistemology

Epistemology is the study of the nature of knowledge. It deals with questions as is there truth and or absolute truth, is there one way or many ways to see something. In research, epistemology manifest itself in several views. The two extremes are positivism and interpretivism.

Positivism

Positivism asserts that all truth can be verified and proven scientifically and can be measured and or observed. This position discounts religious revelation as a source of knowledge as this cannot be verified scientifically. The position of positivist is also derived from realism in that there is an external world out there that needs to be studied.

For researchers, positivism is the foundation of quantitative research. Quantitative researchers try to be objective in their research, they try to avoid coming into contact with whatever they are studying as they do not want to disturb the environment. One of the primary goals is to make generalizations that are applicable in all instances.

For quantitative researchers, they normally have a desire to test a theory. In other words, the develop one example of what they believe is a truth about a phenomenon (a theory) and they test the accuracy of this theory with statistical data. The data determines the accuracy of the theory and the changes that need to be made.

By the late 19th and early 20th centuries, people were looking for alternative ways to approach research. One new approach was interpretivism.

Interpretivism

Interpretivism is the complete opposite of positivism in many ways. Interpretivism asserts that there is no absolute truth but relative truth based on context. There is no single reality but multiple realities that need to be explored and understood.

For interpretist, There is a fluidity in their methods of data collection and analysis. These two steps are often iterative in the same design. Furthermore, intrepretist see themselves not as outside the reality but a player within it. Thus, they often will share not only what the data says but their own view and stance about it.

Qualitative researchers are interpretists. They spend time in the field getting close to their participants through interviews and observations. They then interpret the meaning of these communications to explain a local context specific reality.

While quantitative researchers test theories, qualitative researchers build theories. For qualitative researchers, they gather data and interpret the data by developing a theory that explains the local reality of the context. Since the sampling is normally small in qualitative studies, the theories do not often apply to many.

Conclusion

There is little purpose in debating which view is superior. Both positivism and interpretivism have their place in research. What matters more is to understand your position and preference and to be able to articulate in a reasonable manner. It is often not what a person does and believes that is important as why they believe or do what they do.

Internal Validity

In experimental research design, internal validity is the appropriateness of the inferences made about cause and effects relationships between the independent and dependent variables. If there are threats to internal validity it may mean that the cause and effect relationship you are trying to establish is not real. In general, there are three categories of external validity, which are..,

  • Participant threats
  • Treatment threats
  • Procedural threats

We will not discuss all three categories but will focus on participant threats

Participant Threats

There are several forms of threats to internal validity that relate to participants. Below is a list

  • History
  • Maturation
  • Regression
  • Selection
  • Mortality

History

A historical threat to internal validity is the problem of the passages of time from  the beginning to the end of the experiment. During this elapse of time, the groups involved in the study may have different experiences. These different experiences are history threats. One way to deal with this threat is to be sure that the conditions of the experiment are the same.

Maturation

Maturation threat is the problem of how people change over time during an experiment. These changes make it hard to infer if the results of a study are because of the treatment or because of maturation. One way to deal with this threat is to select participants who develop in similar ways and speed.

Regression

Regression threat is the action of the researcher selecting extreme cases to include in their sample. Eventually, these cases regress to the mean, which impacts the results of the pretest or posttest. One option for overcoming this problem is to avoid outliers when selecting the sample.

Selection

Selection bias is the poor habit of picking people in a non-random why for an experiment Examples of this include choosing mostly ‘smart people for an experiment. Or working with petite women for a study on diet and exercise. Random selection is the strongest way to deal with this threat.

Mortality

Mortality is the lost of participants in a study. It is common for participants in a study to dropout and quit for many reasons. This leads to a decrease in the sample size, which weakens the statistical interpretation. Dealing with this requires using larger sample sizes as well as comparing data of dropouts with those who completed the study.

Conclusion

Internal validity can ruin a paper that has not careful planned out how these threats work together to skew results. Researchers need to have an idea of what threats are out there as well as strategies that can alleviate them.

Comparing Samples in R

Comparing groups is a common goal in statistics. This is done to see if there is a difference between two groups. Understanding the difference can lead to insights based on statistical results. In this post, we will examine the following statistical test for comparing samples.

  • t-test/Wilcoxon test
  • Paired t-test

T-test & Wilcoxon Test

The T-test indicates if there is a significant statistical difference between two groups. This is useful if you know what the difference between the two groups are. For example, if you are measuring height of men and women, if you find that men are taller through a t-test, you can state that gender influences height because the only difference between men and women in this example is their gender.

Below is an example of conducting a t-test in R. In the example, we are looking at if there is a difference in body temperature between beavers who are active versus beavers who are not.

> t.test(temp ~ activ, data = beaver2)

	Welch Two Sample t-test

data:  temp by activ
t = -18.548, df = 80.852, p-value < 2.2e-16
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -0.8927106 -0.7197342
sample estimates:
mean in group 0 mean in group 1 
       37.09684        37.90306

Here is what happened

  1. We use the ‘t.test’ function
  2. Within the ‘t.test’ function we indicate that we want to if there is a difference in ‘temp’ when compared on the factor variable ‘activ’ in the data ‘beaver2’
  3. The output provides a lot of information. The t-stat is -18.58 any number at + 1.96 indicates statistical difference.
  4. Df stands for degrees of freeedom and is used to determine the t-stat and p-value.
  5. The p-value is basically zero. Anything less than 0.05 is considered statistically significant.
  6. Next, we have the 95% confidence interval, which is the range of the difference of the means of the two groups in the population.
  7. Lastly, we have the means of each group. Group 0, the inactive group. had a mean of 37.09684. Group 1. the active group, has a mean of  37.90306.

T-test assumes that the data is normally distributed. When normality is a problem, it is possible to use the Wilcoxon test instead. Below is the script for the Wilcoxon Test using the same example.

> wilcox.test(temp ~ activ, data = beaver2)

	Wilcoxon rank sum test with continuity correction

data:  temp by activ
W = 15, p-value < 2.2e-16
alternative hypothesis: true location shift is not equal to 0

A closer look at the output indicates the same results for the most part. Instead of the t-stat the W-stat is used but the p value is the same for both test.

Paired T-Test

A paired t-test is used when you want to compare how the same group of people respond to different interventions. For example, you might use this for a before and after experiment. We will use the ‘sleep’ data in R  to compare a group of people when they receive different types of sleep medication. The script is below

> t.test(extra ~ group, data = sleep, paired = TRUE)

	Paired t-test

data:  extra by group
t = -4.0621, df = 9, p-value = 0.002833
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -2.4598858 -0.7001142
sample estimates:
mean of the differences 
                  -1.58

Here is what happened

  1. We used the ‘t.test’ function and indicate we want to see if ‘extra’ (amount of sleep) is influenced by ‘group’ (two types of sleep medication.
  2. We add the new argument of ‘paired = TRUE’ this tells R that this is a paired test.
  3. The output is the same information as in the regular t.test. The only differences is at the bottom where R only tells you the difference between the two groups and not the means of each. For this example, the people slept about 1 hour and 30 minutes longer on the second sleep medication when compared to the first.

Conclusion

Comparing samples in R is a simple process of understanding what you want to do. With this knowledge, the script and output are not too challenge even for many beginners

Philosophical Foundations of Research: Ontology

Philosophy is a term that is commonly used but hard to define. To put it simply, philosophy explains an individuals or a groups worldview in general or in a specific context. Such questions as the nature of knowledge, reality, and existence are questions that philosophy tries to answer. There are different schools of thought on these questions and these are what we commonly call philosophies

In this post, we will try to look at ontology, which is the study of the nature of reality. In particular, we will define it as well as explain its influence on research.

Ontology

Ontology is the study of the nature of being. It tries to understand the reality of existence. In this body of philosophy, there are two major camps, ontological realism, and ontological idealism.

Ontological realism believes that reality is objective. In other words, there is one objective reality that is external to each individual person. We are in a reality and we do not create it.

Ontological idealism is the opposite extreme. This philosophy states that there are multiple realities an each depends on the person. My reality is different from your reality and each of us builds our own reality.

Ontological realism is one of the philosophical foundations for quantitative research. Quantitative research is a search for an objective reality that accurately explains whatever is being studied.

For qualitative researchers, ontological idealism is one of their philosophical foundations. Qualitative researchers often support the idea of multiple realities. For them, since there is no objective reality it is necessary to come contact with people to explain their reality.

Something that has been alluded to but not stated specifically is the role of independence and dependence of individuals. Regardless of whether someone ascribes to ontological realism or idealis, there is the factor of whether people or independent of reality or dependent to reality. The level of independence and dependence contributes to other philosophies such as objectivism constructivism and pragmatism.

Objectivism, Constructivism and Pragmatism

Objectivism is the belief that there is a single reality that is independent of the individuals within it. Again this is the common assumption of quantitative research. At the opposite end we have constructivism which states that there are multiple realities and the are dependent on the individuals who make each respective reality.

Pragmatism supports the idea of a single reality with the caveat that it is true if it is useful and works. The application of the idea depends upon the individuals, which pushes pragmatism into the realm of dependence.

Conclusion

From this complex explanation of ontology and research comes the following implications

  • Quantitative and qualitative researchers differ in how they see reality. Quantitative researchers are searching for and attempting to explain a single reality while qualitative researchers are searching for and trying to explain multiple realities.
  • Quantitative and qualitative researchers also differ on the independence of reality. Quantitative researchers see reality as independent of people while qualitative researchers see reality as dependent on people
  • These factors of reality and its dependence shape the methodologies employed by quantitative and qualitative researchers.

Experimental Design: Treatment Conditions and Group Comparision

A key component of experimental design involves making decisions about the manipulation of the treatment conditions. In this post, we will look at the following traits of treatment conditions

  • Treatment Variables
  • Experimental treatment
  • Conditions
  • Interventions
  • Outcomes

Lastly, we will examine group comparison.

One of the most common independent variables in experimental design are treatment and measured variables. Treatment variables are manipulated by the researcher. For example, if you are looking at how sleep affects academic performance, you may manipulate the amount of sleep participants receive in order to determine the relationship between academic performance and sleep.

Measured variables are variables that are measured by are not manipulated by the researcher. Examples include age, gender, height, weight, etc.

An experimental treatment is the intervention of the researcher to alter the conditions of an experiment. This is done by keeping all other factors constant and only manipulating the experimental treatment, it allows for the potential establishment of a cause-effect relationship. In other words, the experimental treatment is a term for the use of a treatment variable.

Treatment variables usually have different conditions or levels in them. For example, if I am looking at sleep’s affect on academic performance. I may manipulate the treatment variable by creating several categories of the amount of sleep. Such as high, medium, and low amounts of sleep.

Intervention is a term that means the actual application of the treatment variables. In other words, I broke my sample into several groups and caused one group to get plenty of sleep the second group to lack a little bit of sleep and the last group got nothing. Experimental treatment and intervention mean the same thing.

The outcome measure is the experience of measuring the outcome variable. In our example, the outcome variable is academic performance.

Group Comparison

Experimental design often focuses on comparing groups. Groups can be compared between groups and within groups. Returning to the example of sleep and academic performance, a between group comparison would be to compare the different groups based on the amount of sleep they received. A within group comparison would be to compare the participants who received the same amount of sleep.

Often there are at least three groups in an experimental study, which are the controlled, comparison, and experimental group. The controlled group receives no intervention or treatment variable. This group often serves as a baseline for comparing the other groups.

The comparison group is exposed to everything but the actual treatment of the study. They are highly similar to the experimental group with the experience of the treatment. Lastly, the experimental group experiences the treatment of the study.

Conclusion

Experiments involve treatment conditions and groups. As such, researchers need to understand their options for treatment conditions as well as what types of groups they should include in a study.

Examining Distributions In R

Normal distribution is an important term in statistics. When we say normal distribution, we are speaking of the traditional bell curve concept. Normal distribution is important because it is often an assumption of inferential statistics that the distribution of data points is normal. Therefore, one of the first things you do when analyzing data is to check for normality.

In this post, we will look at the following ways to assess normality.

  • By graph
  • By plots
  • By test

Checking Normality by Graph

The easiest and crudest way to check for normality is visually through the use of histograms. You simply look at the histogram and determine how closely it resembles a bell.

To illustrate this we will use the ‘beaver2’ data that is already loaded into R. This dataset contains five variables “day”, “time”, “temp”, and “activ” for data about beavers. Day indicates what day it was, time indicates what time it was, temp is the temperature of the beavers, and activ is whether the beavers were active when their temperature was taking. We are going to examine the normality of the temperature of active and inactive. Below is the code

> library(lattice)
> histogram(~temp | factor(activ), data = beaver2)
  1. We loaded the ‘lattice’ package. (If you don’t have this package please download)>
  2. We used the histogram function and indicate the variable ‘temp’ then the union ( | ) followed by the factor variable ‘activ’ (0 = inactive, 1 = active)
  3. Next, we indicate the dataset we are using ‘beaver2’
  4. After pressing ‘enter’ you should see the following

Rplot10

As you look at the histograms, you can say that they are somewhat normal. The peaks of the data are a little high in both. Group 1 is more normal than Group 0. The problem with visual inspection is lack of accuracy in interpretation. This is partially solved by using QQ plots.

Checking Normality by Plots

QQplots are useful for comparing your data with a normally distributed theoretical dataset. The QQplot includes a line of a normal distribution and the data points for your data for comparison. The more closely your data follows the line the more normal it is. Below is the code for doing this with our beaver information.

> qqnorm(beaver2$temp[beaver2$activ==1], main = 'Active')
> qqline(beaver2$temp[beaver2$activ==1])

Here is what we did

  1. We used the ‘qqnorm’ function to make the plot
  2. Within the ‘qqnorm’ function we tell are to use ‘temp’ from the ‘beaver2’ dataset.
  3. From the ‘temp’ variable we subset the values that have a 1 in the ‘activ’ variable.
  4. We give the plot a title by adding ‘main = Active’
  5. Finally, we add the ‘qqline’ using most of the previous information.
  6. Below is how the plot should look

R

Going by sight again. The data still looks pretty good. However, one last test will determine conclusively if the dataset is normal or not.

Checking Normality by Test

The Shapiro-Wilks normality test determines the probability that the data is normally distributed. The lower the probability the less likely that the data is normally distributed. Below is the code and results for the Shapiro test.

> shapiro.test(beaver2$temp[beaver2$activ==1])

	Shapiro-Wilk normality test

data:  beaver2$temp[beaver2$activ == 1]
W = 0.98326, p-value = 0.5583

Here is what happened

  1. We use the ‘shapiro.test’ function for ‘temp’ of only the beavers who are active (activ = 1)
  2. R tells us the p-value is 0.55 or 55%
  3. This means that the probability of our data being normally distributed is 55% which means it is highly likely to be normal.

Conclusion

It is necessary to always test the normality of data before data analysis. The tips presented here provide some framework for accomplishing this.