fbpx

    How to Perform
    Kruskal Wallis
    test in R

    Looking for a Kruskal Wallis test in R? Doing it yourself is always cheaper, but it can also be a lot more time-consuming. If you’re not good at R programming, you can pay someone to do your R task for you.

    What is a Kruskal Wallis test?

    Use the Kruskal-Wallis test to determine whether the medians of two or more groups differ when you have data that are not symmetric, such as skewed data.

    The Kruskal-Wallis test is a non-parametric statistical technique and is an alternative to one-factor ANOVA. This test assumes that we have one continuous dependent variable (e.g. anxiety level, stress level, etc.) and one categorical variable with three or more groups (e.g. marital status, education level, etc.).

    When Should a Kruskal Wallis be Used?

    The Kruskal-Wallis test is a nonparametric alternative to a one-way ANOVA. Non-parametric means that the test doesn’t assume your data comes from a particular distribution. The test doesn’t require the data to be normal but instead uses the rank of the data values instead of the actual data values for the analysis.

    An Example Of the Kruskal Wallis Test 

    For example, Suppose a researcher wants to examine whether there are differences in test scores based on where a student was born. Therefore, we have one independent categorical variable country with three categories (USA, Australia, Europe) and one continuous dependent variable (exam score).

    Therefore, we test the following hypotheses:

    Null hypothesis: There is no significant effect of the country where students were born (USA, Australia, Europe) on exam scores.

    Alternative hypothesis: There is a significant effect of the country where students were born (USA, Australia, Europe) on exam scores.

    R function to Compute Kruskal Wallis Test

    The code to run a Kruskal Wallis Test using R is as follows:

    kruskal.test(DV~ IV, var.equal=TRUE, data = dataframe)

    DV: dependent variable

    IV: Independent variable

    Running Kruskal Wallis test in Rstudio

    In this section, we will show you how to run the Kruskal Wallis H test using the r studio program and how to interpret the test results after we obtain the result of the test. In the first part, we present the r program code and function for the Kruskal Wallis H test. Next, you will see the outputs as a result of running the r codes. In the last section, you can find the interpretation of the Kruskal Wallis H test in APA format.

    # LOAD DATA
    library(readxl)
    Data <- read_excel(“Data.xlsx“)
    # VIEW DATA
    View(Data)
    # NAME VARIABLES
    data <- Data
    country <- data$country
    exams <- data$exams
    # SHOW LEVELS OF CATEGORICAL VARIABLE
    levels(country)

    # SHOW THE MEDIAN OF THE DEPENDENT VARIABLE BY CATEGORICAL VARIABLE
    library(dplyr)
    group_by(data, country) %>% summarise(count = n(), median = median(exams, na.rm = TRUE))

    # PERFORM THE KRUSKAL WALLIS TEST
    kruskal.test(exams ~ country, data = data)

    > group_by(data, country) %>% summarise(count = n(), median = median(exams, na.rm = TRUE))
    ## # A tibble: 3 × 3
    ##   country   count median
    ##   <chr>     <int>  <dbl>
    ## 1 Australia    35     52
    ## 2 Europe       31     58
    ## 3 USA          33     80
    
    > kruskal.test(exams ~ country, data = data)
    ## 
    ##  Kruskal-Wallis rank sum test
    ## 
    ## data:  exams by country
    ## Kruskal-Wallis chi-squared = 3.6755, df = 2, p-value = 0.1592

    Reporting Kruskal Wallis in R

    The Kruskal-Wallis test was conducted to determine whether the country where students were born (USA, Australia, Europe) has an effect on exam scores. The results indicate a non-significant effect, X-squared (2) = 3.68, p = 0.159. We, therefore, fail to reject the null hypothesis and conclude that there is no effect of the country where students were born (USA, Australia, Europe) on exam scores. The median exam score for students born in Australia is 52, for students born in Europe is 58, and for students born in the USA is 80.

    Are you in trouble with RStudio?

    GET HELP FROM US

    There is a lot of statistical software out there, but R is one of the most popular. If you’re a student who needs help with R Studio, there are a few different resources you can turn to. We prepared a page for R tutorial for Beginners. All contents can guide you through Step-by-step R data analysis tutorials and you can see Basic Statistical Analysis Using the R Statistical Package.

    The second option is that you can get help from us, we give R Studio help for students with their assignments, dissertation, or research. Doing it yourself is always cheaper, but it can also be a lot more time-consuming. If you’re not the best at SPSS, then this might not be a good idea. It can take days just to figure out how to do some of the easier things in SPSS. So paying someone to do your R task will save you a ton of time and make your life a lot easier.

    The procedure of the R help service at OnlineSPSS.com is fairly simple. There are three easy-to-follow steps.

    1. Click and Get a FREE Quote
    2. Make the Payment
    3. Get the Solution

    Our purpose is to provide quick, reliable, and understandable information about Rstudio data analysis to our clients.

    Open chat
    1
    Need Data Analysis Help ?
    Hello,
    How may I help you?