This question already has an answer here:
Inverse of Z-Normalize (z-score) Function on Matlab
(1 answer)
Closed 2 years ago.
If you have a data vector you are given that contains only z-scored variables is it possible to reverse the z-score values to get the original measure without using the original measure?
In R Program:
a = runif(100)
az = (a - mean(a))/sd(a)
Can you get back 'a' using JUST 'az'?
No, it is not possible. The reverse transformation requires knowledge of the summary statistics mean(a) and sd(a), which cannot be recovered from the standardized scores.
Related
This question already has answers here:
How to perform a paired t-test in R when all the values are in one column?
(1 answer)
R - fast two sample t test
(2 answers)
Closed 1 year ago.
How do I run a T test comparing groups I and B by there accuracy? enter image description here
The command you are looking for is t.test(). In your case, it should look like:
t.test(accuracy ~ group, data = DATA_NAME)
This question already has answers here:
calculate the mean for each column of a matrix in R
(10 answers)
Closed 4 years ago.
I'm new to R and still learning. I have a matrix with 100 columns and I need to calculate the average of each column and store all those values for further calculations. Each column has 5 numbers and after this step i'm supposed to have 100 new values. Also, please let me know if the replicate() function is a viable way to do this in just one line.
colMeans(DF)
Is a highly optimized function for exactly this purpose.
This question already has answers here:
Calculate cumulative average (mean)
(7 answers)
Closed 5 years ago.
(I am sorry if the term is not correct).
In R, I have a numeric vector x. I want to create new vector y where:
y[i] = mean (x[1:i)
It is easy to write a function to calculate y, but is there a built-in function in R which do the task?
Thank you very much
Try this
y <- cumsum(x) / seq_along(x)
Reference
https://stat.ethz.ch/pipermail/r-help/2008-May/162729.html
This question already has an answer here:
Vector of cumulative sums in R
(1 answer)
Closed 6 years ago.
I'm having real difficulty performing a calculation that is incredibly easy to perform in excel. What i require is a kind of rolling addition whereby the value in one column is added to preceding data point. For example:
column a: 1,2,3,5,16,18,3,11
would produce:
column b: 1,3,6,11,27,45,48,59
i.e. (1+1=2),(2+1=3),(3+3=6),(5+6=11)...
I have a feeling I'm missing something really obvious but have tried various iterations of rollapply and shift with no success... How can I do this in R? What am I missing?
The function you are looking for is cumsum:
df = data.frame(a=1:10)
df$b = cumsum(df$a)
This question already has answers here:
Efficient calculation of matrix cumulative standard deviation in r
(2 answers)
Closed 9 years ago.
I'm trying to calculate the standard deviation of values in a time series, but I'd like to do it incrementally by advancing one day from the initial date value each time. I know there is a way to do this in R (probably using ddply?) that doesn't involve a nasty for-loop. Thanks for any help!
d<-seq(from=as.Date("2013-01-01"), to=as.Date("2013-02-01"), by="day")
v <-rnorm(32, 10, 5)
test.df<-data.frame(the_date=d, value=v)
Here's the way I'm doing it now.
result <- c()
for(i in 2:nrow(test.df)){ result[i-1] <- sd(test.df[1:i,]$value)}
Use TTR::runSD with cumulative=TRUE.
library(TTR)
x <- xts(test.df[,2],test.df[,1])
runSD(x, n=1, cumulative=TRUE)