# Set seed for reproducibility
set.seed(42)
# Simulate 200 firms
n <- 200
firm_size <- runif(n, 10, 500) # Total Assets
# Generate R&D expenditure
error <- rnorm(n, mean = 0, sd = 0.5)
rd_expenditure <- exp(1.5 + 0.6 * log(firm_size) + error)
# Create dataframe
df_firms <- data.frame(
Firm_ID = 1:n,
Total_Assets = firm_size,
RD_Expenditure = rd_expenditure
)
# Preview data
head(df_firms)
## Firm_ID Total_Assets RD_Expenditure
## 1 1 458.2550 322.76939
## 2 2 469.1670 302.76313
## 3 3 150.2084 54.90529
## 4 4 416.9193 421.56611
## 5 5 324.4553 103.12089
## 6 6 264.3570 134.17397
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.5.2
ggplot(df_firms, aes(x = Total_Assets, y = RD_Expenditure)) +
geom_point(color = "blue") +
labs(
title = "Relationship Between Firm Size and R&D Expenditure",
x = "Total Assets (Firm Size)",
y = "R&D Expenditure"
)

model <- lm(RD_Expenditure ~ Total_Assets, data = df_firms)
summary(model)
##
## Call:
## lm(formula = RD_Expenditure ~ Total_Assets, data = df_firms)
##
## Residuals:
## Min 1Q Median 3Q Max
## -135.79 -42.06 -12.37 25.08 404.97
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 40.50788 11.25914 3.598 0.000405 ***
## Total_Assets 0.35091 0.03731 9.405 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 75.31 on 198 degrees of freedom
## Multiple R-squared: 0.3088, Adjusted R-squared: 0.3053
## F-statistic: 88.46 on 1 and 198 DF, p-value: < 2.2e-16
par(mfrow=c(2,2))
plot(model)

model_log <- lm(log(RD_Expenditure) ~ log(Total_Assets), data = df_firms)
summary(model_log)
##
## Call:
## lm(formula = log(RD_Expenditure) ~ log(Total_Assets), data = df_firms)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.31707 -0.31284 -0.00069 0.30462 1.38376
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.4356 0.2100 6.837 9.82e-11 ***
## log(Total_Assets) 0.6075 0.0389 15.616 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4815 on 198 degrees of freedom
## Multiple R-squared: 0.5519, Adjusted R-squared: 0.5496
## F-statistic: 243.9 on 1 and 198 DF, p-value: < 2.2e-16
par(mfrow=c(2,2))
plot(model_log)
