<jupyter_start><jupyter_text>Multiple regression First I generated the random variables A and B (with correlation 0.2).Then I made the variable Y, which is dependent on A and A*B.<jupyter_code># generate correlated random variables A and B

library(MASS)

rawvars <- mvrnorm(n=100, mu=c(0,0), Sigma=matrix(c(0.3,0.05,0.05,0.3),nrow=2))
A <- rawvars[,1]
B <- rawvars[,2]

# making a model with a main effect of a and an interaction effect of b
Y = 0.5*A - 2*A*B + rnorm(100,0,0.2)<jupyter_output>correlation between A and B (rho):  1.075699
correlation between A and Y (rho):  7.428078
correlation between B and Y (rho):  -2.647305
correlation between A and B (pvalue):  0.2847029
correlation between A and Y (pvalue):  4.123057e-11
correlation between B and Y (pvalue):  0.009455369<jupyter_text>Below you can see that all variables have a significant correlation<jupyter_code>cat("correlation between A and B (rho): ",cor.test(A,B)$statistic)
cat("\ncorrelation between A and Y (rho): ",cor.test(A,Y)$statistic)
cat("\ncorrelation between B and Y (rho): ",cor.test(B,Y)$statistic)
cat("correlation between A and B (pvalue): ",cor.test(A,B)$p.value)
cat("\ncorrelation between A and Y (pvalue): ",cor.test(A,Y)$p.value)
cat("\ncorrelation between B and Y (pvalue): ",cor.test(B,Y)$p.value)<jupyter_output>correlation between A and B (pvalue):  0.2847029
correlation between A and Y (pvalue):  4.123057e-11
correlation between B and Y (pvalue):  0.009455369<jupyter_text>Even if you look on a figure you can see that B and Y are related.<jupyter_code>plot(B,Y,pch=16,cex=0.6)<jupyter_output><empty_output><jupyter_text>But in the multiple regression, the main effect becomes (correctly) non-significant.<jupyter_code>MulReg = lm(Y~A+B+A*B)
summary(MulReg)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13172645739910313, 'fraction_numerical': 0.06053811659192825, 'mean_word_length': 5.812977099236641, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '589521', 'license': 'MIT', 'n_tokens_mistral': 721, 'n_tokens_neox': 640, 'n_words': 200, 'path': 'collection_I_need_to_sort/.ipynb_checkpoints/MultReg-checkpoint.ipynb', 'repo_name': 'jokedurnez/RandomNotes', 'size': '1784'}