+ Reply to Thread
Results 1 to 9 of 9

Thread: r command for sxx

  1. #1
    Points: 1,493, Level: 21
    Level completed: 93%, Points required for next Level: 7

    Posts
    108
    Thanks
    11
    Thanked 7 Times in 7 Posts

    r command for sxx




    what is the R command for SXX? cant seem to find it on google. thanks
    and sxy while we are at it.

  2. #2
    Probably A Mammal
    Points: 19,342, Level: 87
    Level completed: 99%, Points required for next Level: 8
    bryangoodrich's Avatar
    Location
    Sacramento, California, United States
    Posts
    2,207
    Thanks
    293
    Thanked 498 Times in 453 Posts

    Re: r command for sxx

    Do you mean SSx? The sum of squares of x

    = \sum (X - \overline{X})^2

    and,

    Sxy = \sum (X - \overline{X})(Y - \overline{Y})

  3. #3
    Points: 1,493, Level: 21
    Level completed: 93%, Points required for next Level: 7

    Posts
    108
    Thanks
    11
    Thanked 7 Times in 7 Posts

    Re: r command for sxx

    yes exactly. it is referred to as SXX and not SSX in my book, but the equations are the same.
    Last edited by interestednew; 06-21-2011 at 11:45 PM.

  4. #4
    Beep
    Points: 63,426, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardCommunity AwardFrequent PosterActivity Award
    Dason's Avatar
    Location
    Ames, IA
    Posts
    11,334
    Thanks
    266
    Thanked 2,204 Times in 1,883 Posts

    Re: r command for sxx

    There isn't something that directly gives it to you but it's pretty easy to program yourself
    Code: 
    SXX <- sum((x - mean(x))^2)
    # alternatively
    SXX <- (length(x)-1)*var(x)

  5. #5
    Points: 1,493, Level: 21
    Level completed: 93%, Points required for next Level: 7

    Posts
    108
    Thanks
    11
    Thanked 7 Times in 7 Posts

    Re: r command for sxx

    Yeah haha I guess thats pretty trivial. I had one more R command question (for now anyway), I ran a linear regression in R and got the estimated intercept and slope. I know how to get their CI in R but I was wondering if there was a way to get CI for a specified X value. thanks

  6. #6
    Beep
    Points: 63,426, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardCommunity AwardFrequent PosterActivity Award
    Dason's Avatar
    Location
    Ames, IA
    Posts
    11,334
    Thanks
    266
    Thanked 2,204 Times in 1,883 Posts

    Re: r command for sxx

    Use the "predict" function setting the "interval" parameter to "confidence". You can also get prediction intervals by setting interval to "prediction" instead.

  7. #7
    Points: 1,493, Level: 21
    Level completed: 93%, Points required for next Level: 7

    Posts
    108
    Thanks
    11
    Thanked 7 Times in 7 Posts

    Re: r command for sxx

    Ok thanks that got me going.....what I cant seem to do is use predict to get a confidence interval for an X value that is not part of my data.


    Code: 
    predict(lm(Y~X),interval=c("confidence"),level=0.95)
    say I want to predict x=4 (which is not one of my X values in the model)

  8. #8
    Probably A Mammal
    Points: 19,342, Level: 87
    Level completed: 99%, Points required for next Level: 8
    bryangoodrich's Avatar
    Location
    Sacramento, California, United States
    Posts
    2,207
    Thanks
    293
    Thanked 498 Times in 453 Posts

    Re: r command for sxx

    You have to specify the new data you want to predict by the "newdata" argument (see help file for details). Just remember, it needs to be a dataframe of the same variable. So if you have, for instance, Y ~ X, then you want to issue a command like

    Code: 
    predict(lm(Y ~ X), newdata = data.frame(X = c(10, 20, 30)), int = "confidence", level = 0.90)
    Otherwise, predict uses fitted values by default.

  9. #9
    Probably A Mammal
    Points: 19,342, Level: 87
    Level completed: 99%, Points required for next Level: 8
    bryangoodrich's Avatar
    Location
    Sacramento, California, United States
    Posts
    2,207
    Thanks
    293
    Thanked 498 Times in 453 Posts

    Re: r command for sxx


    Also, with respect to the sum of squared deviations mentioned earlier (and sxx is the notation), there are a number of matrix ways to get it. For instance, consider a Y vector of response values. You can get \sum Y^2 with

    Code: 
    t(Y) %*% as.matrix(Y)
    I don't have my book handy (just moved), but there are similar matrix methods to get the various sum of squares and squared deviations (from the mean) in a nice matrix form. You should be able to find it in any statistics book on regressions. It goes along with solving the normal equations.

+ Reply to Thread

           




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts






Advertise on Talk Stats