correlation

How to generate a binomial vector of n correlated items?

孤者浪人 提交于 2019-12-12 21:05:38
问题 I want to generate a binomial vector based on a number of correlated items each with a defined probability. When I use e. g. rbinom(1e3, size = 4, prob = c(p.x1, p.x2, p.x3, p.x4)) I'm getting something like 3 3 0 0 2 4 1 0 4 4 0 1 4... . Now these x_i have adefined probabilities but are not correlated. Five years ago Josh O'Brien contributed a great approach to generate correlated binomial data. I think it is close towards my needs, but it is designed for pairs, and I want 1., a single

How to change the margins of a correlation matrix plot?

你。 提交于 2019-12-12 18:26:00
问题 I couldn't find any option to expand the margins for plot generated by corrplot.mixed in the corrplot package. Any suggestion would be appreciated! library(corrplot) cor_matrix <- structure(c(1, 0.31596392056465, -0.120092224085334, -0.345097115278159, 0.31596392056465, 1, 0.158912865564527, -0.606426850726639, -0.120092224085334, 0.158912865564527, 1, -0.134795548155303, -0.345097115278159, -0.606426850726639, -0.134795548155303, 1), .Dim = c(4L, 4L), .Dimnames = list(NULL, c("var_1", "var_2

Calculate correlation of data generated by function in R

随声附和 提交于 2019-12-12 16:27:44
问题 I have created the following function in R : timeseriesmodel <- function(N, x0, delta, variance) { z<-cumsum(rnorm(n=N, mean=0, sd=sqrt(variance))) t<-1:N x<-x0+t*delta+z return(x)} This function returns a vector 'x' of length 'N', representing the data points of a random walk with drift. In my case: timeseriesmodel(250,1,0,1.2) Now I should repeat this function 100 times, ending up with 100 timeseries data sets of length 250. Then I have to estimate the correlation between the 249th and

Correlation matrix heatmap with multiple datasets that have matching columns

邮差的信 提交于 2019-12-12 16:14:19
问题 If we have three datasets: X = pd.DataFrame({"t":[1,2,3,4,5],"A":[34,12,78,84,26], "B":[54,87,35,25,82], "C":[56,78,0,14,13], "D":[0,23,72,56,14], "E":[78,12,31,0,34]}) Y = pd.DataFrame({"t":[1,2,3,4,5],"A":[45,24,65,65,65], "B":[45,87,65,52,12], "C":[98,52,32,32,12], "D":[0,23,1,365,53], "E":[24,12,65,3,65]}) Z = pd.DataFrame({"t":[1,2,3,4,5],"A":[14,96,25,2,25], "B":[47,7,5,58,34], "C":[85,45,65,53,53], "D":[3,35,12,56,236], "E":[68,10,45,46,85]}) Where "t" is an index. How could one output

Calculating correlations between every item in a list

自古美人都是妖i 提交于 2019-12-12 16:02:27
问题 I'm trying to calculate the Pearson correlation correlation between every item in my list. I'm trying to get the correlations between data[0] and data[1], data[0] and data[2], and data[1] and data[2]. import scipy from scipy import stats data = [[1, 2, 4], [9, 5, 1], [8, 3, 3]] def pearson(x, y): series1 = data[x] series2 = data[y] if x != y: return scipy.stats.pearsonr(series1, series2) h = [pearson(x,y) for x,y in range(0, len(data))] This returns the error TypeError: 'int' object is not

how to place colorlegend (corrplot) in graphic

谁说胖子不能爱 提交于 2019-12-12 09:49:03
问题 I am using corrplot to create a correlation heatmap, but I don't like the default legend - it is too big. So I was trying to use the colorlegend() to add the legend after I create the plot (and disable the default legend with cl.pos="n" ). Only problem is that I can't figure out how to change the position of the legend - it ends up on the lower left. Ideally, I could place it on the top right, but I looked through the options for colorlegend and plot and can't figure this out. For example: #

How to have diagonal labels in R Corrgram?

非 Y 不嫁゛ 提交于 2019-12-12 06:53:12
问题 Corrgram docs have been misleading, since 2012, as discussed in the email thread how to change variable names in corrgram diagonal about putting labels on the diagonal. Many users think wrongly that diag.panel=... is the solution but it is not as seen in the following, but I cannot use labels because it is still not yet documented yes, the argument "labels" it's working fine! It would be great if the docs will be be updated also with this already implemented feature Code library("corrgram")

Correlation between two vectors vs. angle between vectors

[亡魂溺海] 提交于 2019-12-12 06:12:42
问题 I am trying to determine if the movement of two objects is "in phase" or opposing each other. So basically I have two vectors, R1, R2 in R^3 and I want to know if they "point in the same direction". I can think of two ways to compute that: a) Calculate the angle between the two vectors. The angle indicates their alignment. b) Calculate the correlation coefficient between the two vectors. (e.g. using Matlab's corr function) 1 means they are parallel, -1 antiparallel. If they are perpendicular

Cor function in R producing errors

眉间皱痕 提交于 2019-12-12 03:42:33
问题 i'v been trying to write a function that takes a directory of data files and a threshold for complete cases and calculates the correlation between sulfate and nitrate for monitor locations where the number of completely observed cases (on all variables) is greater than the threshold. The function should return a vector of correlations for the monitors that meet the threshold requirement. If no monitors meet the threshold requirement, then the function should return a numeric vector of length

Eta/Eta-squared routines in R

只谈情不闲聊 提交于 2019-12-11 21:12:23
问题 Apart from graphical estimation of linearity (gaze-at-scatterplot method), which is utilized before applying some technique from GLM family, there are several ways to do this estimation arithmetically (i.e. without graphs). Right now, I'll focus on Fisher's eta-squared - correlation ratio: arithmetically, it's equal to squared Pearson's r (coef. of determination: r 2 ) if relationship between two variables is linear. Hence, you can compare values of eta and r and make an assessment about type