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

  • Home
  • SEARCH
  • 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 9212915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:37:54+00:00 2026-06-18T01:37:54+00:00

Essentially, I want to build a spider plot for sensitivity analysis. I want to

  • 0

Essentially, I want to build a spider plot for sensitivity analysis. I want to split my data into 10 tranches, and find the mean result value (in column 4) for each tranche. The tranches should be selected based on the 10th, 20th, 30th, 40th, etc. percentiles for the data in each of the variable columns. I got this to work, but I’m thinking that there must be a much easier way to do it.

My code:

##Make some data and put it into a matrix.

c <- 1000
v1 <- rnorm (c, 100, 15)
v2 <- rnorm (c, 80, 10)
v3 <- rnorm (c, 50, 5)
r1 <- ((v1*v2^2)/v3)
data <- cbind (v1,v2)
data <- cbind (data, v3)
data <- cbind (data, r1)

##Sort matrix by first column.
data <- as.matrix(data[order(data[,1]),])

##Find mean of column 4 values corresponding to the smallest 10% (and 20%, and 30%,     etc.) of column 1 values.
a1 <- mean (data[1:(c/10),4])
a2 <- mean (data[(c/10):(2*c/10),4])
a3 <- mean (data[(2*c/10):(3*c/10),4])
a4 <- mean (data[(3*c/10):(4*c/10),4])
a5 <- mean (data[(4*c/10):(5*c/10),4])
a6 <- mean (data[(5*c/10):(6*c/10),4])
a7 <- mean (data[(6*c/10):(7*c/10),4])
a8 <- mean (data[(7*c/10):(8*c/10),4])
a9 <- mean (data[(8*c/10):(9*c/10),4])
a10 <- mean (data[(9*c/10):c,4])

##Combine into a vector.
a <- as.vector(c(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10))

##Repeat for data sorted by columns 2 and 3 respectively.
data <- as.matrix(data[order(data[,2]),])

a1 <- mean (data[1:(c/10),4])
a2 <- mean (data[(c/10):(2*c/10),4])
a3 <- mean (data[(2*c/10):(3*c/10),4])
a4 <- mean (data[(3*c/10):(4*c/10),4])
a5 <- mean (data[(4*c/10):(5*c/10),4])
a6 <- mean (data[(5*c/10):(6*c/10),4])
a7 <- mean (data[(6*c/10):(7*c/10),4])
a8 <- mean (data[(7*c/10):(8*c/10),4])
a9 <- mean (data[(8*c/10):(9*c/10),4])
a10 <- mean (data[(9*c/10):c,4])

b <- as.vector(c(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10))

data <- as.matrix(data[order(data[,3]),])

a1 <- mean (data[1:(c/10),4])
a2 <- mean (data[(c/10):(2*c/10),4])
a3 <- mean (data[(2*c/10):(3*c/10),4])
a4 <- mean (data[(3*c/10):(4*c/10),4])
a5 <- mean (data[(4*c/10):(5*c/10),4])
a6 <- mean (data[(5*c/10):(6*c/10),4])
a7 <- mean (data[(6*c/10):(7*c/10),4])
a8 <- mean (data[(7*c/10):(8*c/10),4])
a9 <- mean (data[(8*c/10):(9*c/10),4])
a10 <- mean (data[(9*c/10):c,4])

d <- as.vector(c(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10))

##Make a pretty chart
plot (a, type = "o", col = "red") 
lines (b, type = "o", col = "blue") 
lines (d, type = "o", col = "green") 
  • 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-06-18T01:37:56+00:00Added an answer on June 18, 2026 at 1:37 am

    Here is some code that does the same thing, but a more compactly and idiomatically for R.

    n <- 1000
    # changed from c to n since you use c again later as something else
    v1 <- rnorm (n, 100, 15)
    v2 <- rnorm (n, 80, 10)
    v3 <- rnorm (n, 50, 5)
    r1 <- ((v1*v2^2)/v3)
    
    DF <- data.frame(v1, v2, v3, r1)
    # A data.frame seems like it would be a better fit for this
    
    library("Hmisc")
    # The Hmisc package has a function which splits in to quantiles, so use it
    DF <- transform(DF, 
                    v1.decile = cut2(v1, g=10),
                    v2.decile = cut2(v2, g=10),
                    v3.decile = cut2(v3, g=10))
    # add three new variables to the data frame which indicate which decile each
    # value belongs to, for each of v1, v2, and v3
    a <- aggregate(DF$r1, list(DF$v1.decile), mean)$x
    # why add the new variables? because aggregate can perform an operation on
    # groups of one variable defined by the value of another variable
    b <- aggregate(DF$r1, list(DF$v2.decile), mean)$x
    c <- aggregate(DF$r1, list(DF$v3.decile), mean)$x
    

    Then you can make the plot like you did before.


    EDIT:

    Ananda Mahto’s answer pointed out the function version of the aggregate function which I had forgotten about. You could write the aggregate lines more clearly as

    a <- aggregate(r1 ~ v1.decile, DF, mean)$r1
    b <- aggregate(r1 ~ v2.decile, DF, mean)$r1
    c <- aggregate(r1 ~ v3.decile, DF, mean)$r1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've gotten myself into a situation that seems fairly unusual, and essentially want to
I essentially want to display a screen whenever the screen is unlocked regardless of
Essentially I want a border-less, black window which I can set the location and
Essentially I want to suck a line of text from a file, assign the
I have 3 date range forms on my site. Essentially I want to hide
Essentially what I want to do is to apply additional CSS classes to individual
If I want to essentially grep every line ever in the repository, is there
Essentially, what I want to do (in DirectX) is to take two partially-transparent images
I want to store a list of numbers (essentially, a set in mathematical terms)
I want to implement a view in an iPhone application that is essentially like

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.