Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6988717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:07:05+00:00 2026-05-27T19:07:05+00:00

I am using the kmeans() function in R and I was curious what is

  • 0

I am using the kmeans() function in R and I was curious what is the difference between the totss and tot.withinss attributes of the returned object. From the documentation they seem to be returning the same thing, but applied on my dataset the value of totss is 66213.63 and for tot.withinss is 6893.50.
Please let me know if you are familiar with mroe details.
Thank you!

Marius.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:07:06+00:00Added an answer on May 27, 2026 at 7:07 pm

    Given the between sum of squares betweenss and the vector of within sum of squares for each cluster withinss the formulas are these:

    totss = tot.withinss + betweenss
    tot.withinss = sum(withinss)
    

    For example, if there were only one cluster then betweenss would be 0, there would be only one component in withinss and totss = tot.withinss = withinss.

    For further clarification, we can compute these various quantities ourselves given the cluster assignments and that may help clarify their meanings. Consider the data x and the cluster assignments cl$cluster from the example in help(kmeans). Define the sum of squares function as follows — this subtracts the mean of each column of x from that column and then sums of the squares of each element of the remaining matrix:

    # or ss <- function(x) sum(apply(x, 2, function(x) x - mean(x))^2)
    ss <- function(x) sum(scale(x, scale = FALSE)^2)
    

    Then we have the following. Note that cl$centers[cl$cluster, ] are the fitted values, i.e. it iis a matrix with one row per point such that the ith row is the center of the cluster that the ith point belongs to.

    example(kmeans) # create x and cl
    
    betweenss <- ss(cl$centers[cl$cluster,]) # or ss(fitted(cl))
    
    withinss <- sapply(split(as.data.frame(x), cl$cluster), ss)
    tot.withinss <- sum(withinss) # or  resid <- x - fitted(cl); ss(resid)
    
    totss <- ss(x) # or tot.withinss + betweenss
    
    cat("totss:", totss, "tot.withinss:", tot.withinss, 
      "betweenss:", betweenss, "\n")
    
    # compare above to:
    
    str(cl)
    

    EDIT:

    Since this question was answered, R has added additional similar kmeans examples (example(kmeans)) and a new fitted.kmeans method and we now show how the fitted method fits into the above in the comments trailing the code lines.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using kmeans function in matlab for clustering of my dataset. Im interested in
Using jQuery rotate http://code.google.com/p/jqueryrotate/wiki/Examples to animate an object from 0 degrees to 40 degrees
I'm using Opencv's K-means implementation to cluster a large set of 8-dimensional vectors. They
I am using Windows 7 64 bit. I have these imports from scikits.audiolab import
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
I need to use the kmeans function on a rgb image. Each element of
Using jQuery, how do I get the value from a textbox and then load
I am trying to create a clustered image from data being returned from the
So, I'm doing some Kmeans classification using numpy arrays that are quite sparse-- lots
Using mercurial, I've run into an odd problem where a line from one committer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.