Calculating absolute, relative, and cumulative frequencies in R
up vote
1
down vote
favorite
I have two variables, X and Y:
x <- c(1.18,1.42,0.69,0.88,1.69,1.09,1.53,1.02,1.19,1.32)
y <- c(1.72,1.42,1.69,0.79,1.79,0.77,1.44,1.29,1.96,0.99)
I would like to create a table of the absolute, relative and cumulative frequencies of both X and Y in R
plot(table(x)/length(x), type ="h", ylab = "Relative Frequency", xlim = c(0.6,1.8))
plot(table(y)/length(y), type ="h", ylab = "Relative Frequency", xlim = c(0.6,1.8))
I did a sample of the relative frequency but it came out like this: plot of the relative frequency. I think it is wrong. What do you think? Also, how can I use hist(x)$counts
to obtain the absolute and cumulative frequencies?
r statistics
add a comment |
up vote
1
down vote
favorite
I have two variables, X and Y:
x <- c(1.18,1.42,0.69,0.88,1.69,1.09,1.53,1.02,1.19,1.32)
y <- c(1.72,1.42,1.69,0.79,1.79,0.77,1.44,1.29,1.96,0.99)
I would like to create a table of the absolute, relative and cumulative frequencies of both X and Y in R
plot(table(x)/length(x), type ="h", ylab = "Relative Frequency", xlim = c(0.6,1.8))
plot(table(y)/length(y), type ="h", ylab = "Relative Frequency", xlim = c(0.6,1.8))
I did a sample of the relative frequency but it came out like this: plot of the relative frequency. I think it is wrong. What do you think? Also, how can I use hist(x)$counts
to obtain the absolute and cumulative frequencies?
r statistics
Are x and y individual observations or are they variables? Also, please do not use links to questions since users cannot download or manipulate them.
– Harro Cyranka
Nov 11 at 19:57
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have two variables, X and Y:
x <- c(1.18,1.42,0.69,0.88,1.69,1.09,1.53,1.02,1.19,1.32)
y <- c(1.72,1.42,1.69,0.79,1.79,0.77,1.44,1.29,1.96,0.99)
I would like to create a table of the absolute, relative and cumulative frequencies of both X and Y in R
plot(table(x)/length(x), type ="h", ylab = "Relative Frequency", xlim = c(0.6,1.8))
plot(table(y)/length(y), type ="h", ylab = "Relative Frequency", xlim = c(0.6,1.8))
I did a sample of the relative frequency but it came out like this: plot of the relative frequency. I think it is wrong. What do you think? Also, how can I use hist(x)$counts
to obtain the absolute and cumulative frequencies?
r statistics
I have two variables, X and Y:
x <- c(1.18,1.42,0.69,0.88,1.69,1.09,1.53,1.02,1.19,1.32)
y <- c(1.72,1.42,1.69,0.79,1.79,0.77,1.44,1.29,1.96,0.99)
I would like to create a table of the absolute, relative and cumulative frequencies of both X and Y in R
plot(table(x)/length(x), type ="h", ylab = "Relative Frequency", xlim = c(0.6,1.8))
plot(table(y)/length(y), type ="h", ylab = "Relative Frequency", xlim = c(0.6,1.8))
I did a sample of the relative frequency but it came out like this: plot of the relative frequency. I think it is wrong. What do you think? Also, how can I use hist(x)$counts
to obtain the absolute and cumulative frequencies?
r statistics
r statistics
edited Nov 11 at 20:18
Adam Liss
40.4k1193130
40.4k1193130
asked Nov 11 at 19:18
A_1960
102
102
Are x and y individual observations or are they variables? Also, please do not use links to questions since users cannot download or manipulate them.
– Harro Cyranka
Nov 11 at 19:57
add a comment |
Are x and y individual observations or are they variables? Also, please do not use links to questions since users cannot download or manipulate them.
– Harro Cyranka
Nov 11 at 19:57
Are x and y individual observations or are they variables? Also, please do not use links to questions since users cannot download or manipulate them.
– Harro Cyranka
Nov 11 at 19:57
Are x and y individual observations or are they variables? Also, please do not use links to questions since users cannot download or manipulate them.
– Harro Cyranka
Nov 11 at 19:57
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
I'm not sure why you wish to use hist(x)
. Everything can be obtained using table
:
# Absolute frequencies
table(x)
# x
# 0.69 0.88 1.02 1.09 1.18 1.19 1.32 1.42 1.53 1.69
# 1 1 1 1 1 1 1 1 1 1
# Relative frequencies
table(x) / length(x)
# x
# 0.69 0.88 1.02 1.09 1.18 1.19 1.32 1.42 1.53 1.69
# 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
# Cumulative frequencies
cumsum(table(x))
# 0.69 0.88 1.02 1.09 1.18 1.19 1.32 1.42 1.53 1.69
# 1 2 3 4 5 6 7 8 9 10
and the same for y
. As to put them together,
rbind(Absolute = table(x),
Relative = table(x) / length(x),
Cumulative = cumsum(table(x)))
# 0.69 0.88 1.02 1.09 1.18 1.19 1.32 1.42 1.53 1.69
# Absolute 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
# Relative 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
# Cumulative 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0
The results are correct, although indeed somewhat boring. If you have more data, with repetitions, it will look better.
is it normal to get 1 for all the absolute frequencies !! and hist(x)$counts it's an extra for me to capture the difference between x, y which i wanna ask you but I wanna send my plot but I'm new to SOF so no clue
– A_1960
Nov 11 at 20:31
1
As I said, yes, 1 for all the absolute frequencies is correct in this case. A frequency is simply the number of times this value appears in your data. Since all your values are distinct, their frequencies are all 1. Now histogram doesn't show absolute frequencies. It selects bins: in the case ofx
, six bins of width 0.2, from 0.6 to 1.8. Then it computes absolute frequencies with respect to those bins. That may also be useful to you, but the answer to your original question is in my post.
– Julius Vainora
Nov 11 at 20:36
thanks.- but what can be the difference between the two histograms of x and y doing "hist(x)$counts" "hist(y)$counts" if I should give an opinion about it ?
– A_1960
Nov 11 at 20:40
I guess that's not what you mean, but if you wanted to literally look at their difference, you could doc(hist(x)$counts,0) - hist(y)$counts
. I added a zero tox
's histogram because it has one bin less (with no values there). This shows you differences of absolute differences of those discretized values (i.e., with respect to bins). Also you may plot those two histograms together and compare. You have little data, so it's hard to say something. In any case, knowing whatx
andy
are is important. Anyway, that's not what you initial question is about.
– Julius Vainora
Nov 11 at 20:47
...If you want more help regarding interpretation of your results, I suggest to ask another question on stats.stackexchange.com
– Julius Vainora
Nov 11 at 20:47
|
show 2 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
I'm not sure why you wish to use hist(x)
. Everything can be obtained using table
:
# Absolute frequencies
table(x)
# x
# 0.69 0.88 1.02 1.09 1.18 1.19 1.32 1.42 1.53 1.69
# 1 1 1 1 1 1 1 1 1 1
# Relative frequencies
table(x) / length(x)
# x
# 0.69 0.88 1.02 1.09 1.18 1.19 1.32 1.42 1.53 1.69
# 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
# Cumulative frequencies
cumsum(table(x))
# 0.69 0.88 1.02 1.09 1.18 1.19 1.32 1.42 1.53 1.69
# 1 2 3 4 5 6 7 8 9 10
and the same for y
. As to put them together,
rbind(Absolute = table(x),
Relative = table(x) / length(x),
Cumulative = cumsum(table(x)))
# 0.69 0.88 1.02 1.09 1.18 1.19 1.32 1.42 1.53 1.69
# Absolute 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
# Relative 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
# Cumulative 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0
The results are correct, although indeed somewhat boring. If you have more data, with repetitions, it will look better.
is it normal to get 1 for all the absolute frequencies !! and hist(x)$counts it's an extra for me to capture the difference between x, y which i wanna ask you but I wanna send my plot but I'm new to SOF so no clue
– A_1960
Nov 11 at 20:31
1
As I said, yes, 1 for all the absolute frequencies is correct in this case. A frequency is simply the number of times this value appears in your data. Since all your values are distinct, their frequencies are all 1. Now histogram doesn't show absolute frequencies. It selects bins: in the case ofx
, six bins of width 0.2, from 0.6 to 1.8. Then it computes absolute frequencies with respect to those bins. That may also be useful to you, but the answer to your original question is in my post.
– Julius Vainora
Nov 11 at 20:36
thanks.- but what can be the difference between the two histograms of x and y doing "hist(x)$counts" "hist(y)$counts" if I should give an opinion about it ?
– A_1960
Nov 11 at 20:40
I guess that's not what you mean, but if you wanted to literally look at their difference, you could doc(hist(x)$counts,0) - hist(y)$counts
. I added a zero tox
's histogram because it has one bin less (with no values there). This shows you differences of absolute differences of those discretized values (i.e., with respect to bins). Also you may plot those two histograms together and compare. You have little data, so it's hard to say something. In any case, knowing whatx
andy
are is important. Anyway, that's not what you initial question is about.
– Julius Vainora
Nov 11 at 20:47
...If you want more help regarding interpretation of your results, I suggest to ask another question on stats.stackexchange.com
– Julius Vainora
Nov 11 at 20:47
|
show 2 more comments
up vote
1
down vote
accepted
I'm not sure why you wish to use hist(x)
. Everything can be obtained using table
:
# Absolute frequencies
table(x)
# x
# 0.69 0.88 1.02 1.09 1.18 1.19 1.32 1.42 1.53 1.69
# 1 1 1 1 1 1 1 1 1 1
# Relative frequencies
table(x) / length(x)
# x
# 0.69 0.88 1.02 1.09 1.18 1.19 1.32 1.42 1.53 1.69
# 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
# Cumulative frequencies
cumsum(table(x))
# 0.69 0.88 1.02 1.09 1.18 1.19 1.32 1.42 1.53 1.69
# 1 2 3 4 5 6 7 8 9 10
and the same for y
. As to put them together,
rbind(Absolute = table(x),
Relative = table(x) / length(x),
Cumulative = cumsum(table(x)))
# 0.69 0.88 1.02 1.09 1.18 1.19 1.32 1.42 1.53 1.69
# Absolute 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
# Relative 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
# Cumulative 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0
The results are correct, although indeed somewhat boring. If you have more data, with repetitions, it will look better.
is it normal to get 1 for all the absolute frequencies !! and hist(x)$counts it's an extra for me to capture the difference between x, y which i wanna ask you but I wanna send my plot but I'm new to SOF so no clue
– A_1960
Nov 11 at 20:31
1
As I said, yes, 1 for all the absolute frequencies is correct in this case. A frequency is simply the number of times this value appears in your data. Since all your values are distinct, their frequencies are all 1. Now histogram doesn't show absolute frequencies. It selects bins: in the case ofx
, six bins of width 0.2, from 0.6 to 1.8. Then it computes absolute frequencies with respect to those bins. That may also be useful to you, but the answer to your original question is in my post.
– Julius Vainora
Nov 11 at 20:36
thanks.- but what can be the difference between the two histograms of x and y doing "hist(x)$counts" "hist(y)$counts" if I should give an opinion about it ?
– A_1960
Nov 11 at 20:40
I guess that's not what you mean, but if you wanted to literally look at their difference, you could doc(hist(x)$counts,0) - hist(y)$counts
. I added a zero tox
's histogram because it has one bin less (with no values there). This shows you differences of absolute differences of those discretized values (i.e., with respect to bins). Also you may plot those two histograms together and compare. You have little data, so it's hard to say something. In any case, knowing whatx
andy
are is important. Anyway, that's not what you initial question is about.
– Julius Vainora
Nov 11 at 20:47
...If you want more help regarding interpretation of your results, I suggest to ask another question on stats.stackexchange.com
– Julius Vainora
Nov 11 at 20:47
|
show 2 more comments
up vote
1
down vote
accepted
up vote
1
down vote
accepted
I'm not sure why you wish to use hist(x)
. Everything can be obtained using table
:
# Absolute frequencies
table(x)
# x
# 0.69 0.88 1.02 1.09 1.18 1.19 1.32 1.42 1.53 1.69
# 1 1 1 1 1 1 1 1 1 1
# Relative frequencies
table(x) / length(x)
# x
# 0.69 0.88 1.02 1.09 1.18 1.19 1.32 1.42 1.53 1.69
# 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
# Cumulative frequencies
cumsum(table(x))
# 0.69 0.88 1.02 1.09 1.18 1.19 1.32 1.42 1.53 1.69
# 1 2 3 4 5 6 7 8 9 10
and the same for y
. As to put them together,
rbind(Absolute = table(x),
Relative = table(x) / length(x),
Cumulative = cumsum(table(x)))
# 0.69 0.88 1.02 1.09 1.18 1.19 1.32 1.42 1.53 1.69
# Absolute 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
# Relative 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
# Cumulative 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0
The results are correct, although indeed somewhat boring. If you have more data, with repetitions, it will look better.
I'm not sure why you wish to use hist(x)
. Everything can be obtained using table
:
# Absolute frequencies
table(x)
# x
# 0.69 0.88 1.02 1.09 1.18 1.19 1.32 1.42 1.53 1.69
# 1 1 1 1 1 1 1 1 1 1
# Relative frequencies
table(x) / length(x)
# x
# 0.69 0.88 1.02 1.09 1.18 1.19 1.32 1.42 1.53 1.69
# 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
# Cumulative frequencies
cumsum(table(x))
# 0.69 0.88 1.02 1.09 1.18 1.19 1.32 1.42 1.53 1.69
# 1 2 3 4 5 6 7 8 9 10
and the same for y
. As to put them together,
rbind(Absolute = table(x),
Relative = table(x) / length(x),
Cumulative = cumsum(table(x)))
# 0.69 0.88 1.02 1.09 1.18 1.19 1.32 1.42 1.53 1.69
# Absolute 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
# Relative 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
# Cumulative 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0
The results are correct, although indeed somewhat boring. If you have more data, with repetitions, it will look better.
answered Nov 11 at 20:24
Julius Vainora
29.5k75878
29.5k75878
is it normal to get 1 for all the absolute frequencies !! and hist(x)$counts it's an extra for me to capture the difference between x, y which i wanna ask you but I wanna send my plot but I'm new to SOF so no clue
– A_1960
Nov 11 at 20:31
1
As I said, yes, 1 for all the absolute frequencies is correct in this case. A frequency is simply the number of times this value appears in your data. Since all your values are distinct, their frequencies are all 1. Now histogram doesn't show absolute frequencies. It selects bins: in the case ofx
, six bins of width 0.2, from 0.6 to 1.8. Then it computes absolute frequencies with respect to those bins. That may also be useful to you, but the answer to your original question is in my post.
– Julius Vainora
Nov 11 at 20:36
thanks.- but what can be the difference between the two histograms of x and y doing "hist(x)$counts" "hist(y)$counts" if I should give an opinion about it ?
– A_1960
Nov 11 at 20:40
I guess that's not what you mean, but if you wanted to literally look at their difference, you could doc(hist(x)$counts,0) - hist(y)$counts
. I added a zero tox
's histogram because it has one bin less (with no values there). This shows you differences of absolute differences of those discretized values (i.e., with respect to bins). Also you may plot those two histograms together and compare. You have little data, so it's hard to say something. In any case, knowing whatx
andy
are is important. Anyway, that's not what you initial question is about.
– Julius Vainora
Nov 11 at 20:47
...If you want more help regarding interpretation of your results, I suggest to ask another question on stats.stackexchange.com
– Julius Vainora
Nov 11 at 20:47
|
show 2 more comments
is it normal to get 1 for all the absolute frequencies !! and hist(x)$counts it's an extra for me to capture the difference between x, y which i wanna ask you but I wanna send my plot but I'm new to SOF so no clue
– A_1960
Nov 11 at 20:31
1
As I said, yes, 1 for all the absolute frequencies is correct in this case. A frequency is simply the number of times this value appears in your data. Since all your values are distinct, their frequencies are all 1. Now histogram doesn't show absolute frequencies. It selects bins: in the case ofx
, six bins of width 0.2, from 0.6 to 1.8. Then it computes absolute frequencies with respect to those bins. That may also be useful to you, but the answer to your original question is in my post.
– Julius Vainora
Nov 11 at 20:36
thanks.- but what can be the difference between the two histograms of x and y doing "hist(x)$counts" "hist(y)$counts" if I should give an opinion about it ?
– A_1960
Nov 11 at 20:40
I guess that's not what you mean, but if you wanted to literally look at their difference, you could doc(hist(x)$counts,0) - hist(y)$counts
. I added a zero tox
's histogram because it has one bin less (with no values there). This shows you differences of absolute differences of those discretized values (i.e., with respect to bins). Also you may plot those two histograms together and compare. You have little data, so it's hard to say something. In any case, knowing whatx
andy
are is important. Anyway, that's not what you initial question is about.
– Julius Vainora
Nov 11 at 20:47
...If you want more help regarding interpretation of your results, I suggest to ask another question on stats.stackexchange.com
– Julius Vainora
Nov 11 at 20:47
is it normal to get 1 for all the absolute frequencies !! and hist(x)$counts it's an extra for me to capture the difference between x, y which i wanna ask you but I wanna send my plot but I'm new to SOF so no clue
– A_1960
Nov 11 at 20:31
is it normal to get 1 for all the absolute frequencies !! and hist(x)$counts it's an extra for me to capture the difference between x, y which i wanna ask you but I wanna send my plot but I'm new to SOF so no clue
– A_1960
Nov 11 at 20:31
1
1
As I said, yes, 1 for all the absolute frequencies is correct in this case. A frequency is simply the number of times this value appears in your data. Since all your values are distinct, their frequencies are all 1. Now histogram doesn't show absolute frequencies. It selects bins: in the case of
x
, six bins of width 0.2, from 0.6 to 1.8. Then it computes absolute frequencies with respect to those bins. That may also be useful to you, but the answer to your original question is in my post.– Julius Vainora
Nov 11 at 20:36
As I said, yes, 1 for all the absolute frequencies is correct in this case. A frequency is simply the number of times this value appears in your data. Since all your values are distinct, their frequencies are all 1. Now histogram doesn't show absolute frequencies. It selects bins: in the case of
x
, six bins of width 0.2, from 0.6 to 1.8. Then it computes absolute frequencies with respect to those bins. That may also be useful to you, but the answer to your original question is in my post.– Julius Vainora
Nov 11 at 20:36
thanks.- but what can be the difference between the two histograms of x and y doing "hist(x)$counts" "hist(y)$counts" if I should give an opinion about it ?
– A_1960
Nov 11 at 20:40
thanks.- but what can be the difference between the two histograms of x and y doing "hist(x)$counts" "hist(y)$counts" if I should give an opinion about it ?
– A_1960
Nov 11 at 20:40
I guess that's not what you mean, but if you wanted to literally look at their difference, you could do
c(hist(x)$counts,0) - hist(y)$counts
. I added a zero to x
's histogram because it has one bin less (with no values there). This shows you differences of absolute differences of those discretized values (i.e., with respect to bins). Also you may plot those two histograms together and compare. You have little data, so it's hard to say something. In any case, knowing what x
and y
are is important. Anyway, that's not what you initial question is about.– Julius Vainora
Nov 11 at 20:47
I guess that's not what you mean, but if you wanted to literally look at their difference, you could do
c(hist(x)$counts,0) - hist(y)$counts
. I added a zero to x
's histogram because it has one bin less (with no values there). This shows you differences of absolute differences of those discretized values (i.e., with respect to bins). Also you may plot those two histograms together and compare. You have little data, so it's hard to say something. In any case, knowing what x
and y
are is important. Anyway, that's not what you initial question is about.– Julius Vainora
Nov 11 at 20:47
...If you want more help regarding interpretation of your results, I suggest to ask another question on stats.stackexchange.com
– Julius Vainora
Nov 11 at 20:47
...If you want more help regarding interpretation of your results, I suggest to ask another question on stats.stackexchange.com
– Julius Vainora
Nov 11 at 20:47
|
show 2 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252288%2fcalculating-absolute-relative-and-cumulative-frequencies-in-r%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Are x and y individual observations or are they variables? Also, please do not use links to questions since users cannot download or manipulate them.
– Harro Cyranka
Nov 11 at 19:57