<jupyter_start><jupyter_text>Simple Exercise on Overfitting First set p=n<jupyter_code>set.seed(123)
n = 1000

p = n
X<- matrix(rnorm(n*p), n, p)
Y<- rnorm(n)

print("p/n is")
print(p/n)
print("R2 is")
print(summary(lm(Y~X))$r.squared)
print("Adjusted R2 is")
print(summary(lm(Y~X))$adj.r.squared)<jupyter_output>[1] "p/n is"
[1] 1
[1] "R2 is"
[1] 1
[1] "Adjusted R2 is"
[1] NaN<jupyter_text>Second, set p=n/2.<jupyter_code>set.seed(123)
n = 1000

p = n/2
X<- matrix(rnorm(n*p), n, p)
Y<- rnorm(n)

print("p/n is")
print(p/n)
print("R2 is")
print(summary(lm(Y~X))$r.squared)
print("Adjusted R2 is")
print(summary(lm(Y~X))$adj.r.squared)<jupyter_output>[1] "p/n is"
[1] 0.5
[1] "R2 is"
[1] 0.4922339
[1] "Adjusted R2 is"
[1] -0.01654975<jupyter_text>Third, set p/n =.05<jupyter_code>set.seed(123)
n = 1000

p = .05*n
X<- matrix(rnorm(n*p), n, p)
Y<- rnorm(n)

print("p/n is")
print(p/n)
print("R2 is")
print(summary(lm(Y~X))$r.squared)
print("Adjusted R2 is")
print(summary(lm(Y~X))$adj.r.squared)<jupyter_output>[1] "p/n is"
[1] 0.05
[1] "R2 is"
[1] 0.04295907
[1] "Adjusted R2 is"
[1] -0.00746458
{'fraction_non_alphanumeric': 0.2333637192342753, 'fraction_numerical': 0.0902461257976299, 'mean_word_length': 5.458823529411765, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 10, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '355181', 'license': 'MIT', 'n_tokens_mistral': 649, 'n_tokens_neox': 570, 'n_words': 117, 'path': 'R_Notebooks/r-notebook-linear-model-overfiting.ipynb', 'repo_name': 'JannisKueck/14.38_Causal_ML', 'size': '1097'}