Rmd

Quelle

Szenario, Hintergrund

SAT: Scholastic Assessment Test

In den USA nationaler Zugangstest zu Universitäten

GPA: Grade Point Average

Übersetzung der american grades (A+ bis F) in Zahlenwerte (0-4, höher ist besser). GPA ist schulabhängig.

Hintergrund, Szenario, Overview

When deciding whether to admit an applicant, colleges take lots of factors, such as grades, sports, activities, leadership positions, awards, teacher recommendations, and test scores, into consideration. Using SAT scores as a basis of whether to admit a student or not has created some controversy. Among other things, people question whether the SATs are fair and whether they predict college performance.

This study examines the SAT and GPA information of 105 students who graduated from a state university with a B.S. in computer science. Using the grades and test scores from high school, can you predict a student’s college grades?

Questions to Answer Can the math and verbal SAT scores be used to predict college GPA? Are the high school and college GPAs related?

Design Issues The conclusions from this study should not be generalized to students of other majors.

Descriptions of Variables

Variable    Description
high_GPA    High school grade point average
math_SAT    Math SAT score
verb_SAT    Verbal SAT score
comp_GPA    Computer science grade point average
univ_GPA    Overall university grade point average

Alle Bewertungen (SAT, GPAs) sind umso besser, je höher der jeweilige Wert ist.

Data

oder lokal

Vorhersage des universitären Gesamterfolgs aus SAT-Testwerten (Mathematik, Sprache)

Find the regression line for predicting the overall university GPA from both the math SAT score and the verbal SAT score.

Find the regression line for predicting the overall university GPA from both the math SAT score and the verbal SAT score.

ddf <- read.delim("http://md.psych.bio.uni-goettingen.de/data/div/sat.txt")
head(ddf)
##   high_GPA math_SAT verb_SAT comp_GPA univ_GPA
## 1     3.45      643      589     3.76     3.52
## 2     2.78      558      512     2.87     2.91
## 3     2.52      583      503     2.54     2.40
## 4     3.67      685      602     3.83     3.47
## 5     3.24      592      538     3.29     3.47
## 6     2.10      562      486     2.64     2.37
# we test mathematics SAT only
r.m <- lm(univ_GPA ~ math_SAT, data=ddf)
summary(r.m)
## 
## Call:
## lm(formula = univ_GPA ~ math_SAT, data = ddf)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.78921 -0.23669  0.01962  0.23730  0.82748 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.2622924  0.3838157  -0.683    0.496    
## math_SAT     0.0055132  0.0006137   8.983 1.34e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3365 on 103 degrees of freedom
## Multiple R-squared:  0.4393, Adjusted R-squared:  0.4338 
## F-statistic: 80.69 on 1 and 103 DF,  p-value: 1.344e-14
# we check residuals
require(psych)
## Loading required package: psych
psych::describe(r.m$residuals)
##    vars   n mean   sd median trimmed  mad   min  max range  skew kurtosis
## X1    1 105    0 0.33   0.02       0 0.33 -0.79 0.83  1.62 -0.18    -0.56
##      se
## X1 0.03
# now we control predictive power of verbal SAT only
r.v <- lm(univ_GPA ~ verb_SAT, data=ddf)
summary(r.v)
## 
## Call:
## lm(formula = univ_GPA ~ verb_SAT, data = ddf)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.94856 -0.19745  0.03271  0.20373  0.79492 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 0.4080980  0.3199775   1.275    0.205    
## verb_SAT    0.0046187  0.0005316   8.688 6.03e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3414 on 103 degrees of freedom
## Multiple R-squared:  0.4229, Adjusted R-squared:  0.4173 
## F-statistic: 75.48 on 1 and 103 DF,  p-value: 6.034e-14
# we combine mathematical and verbal SAT additively
r.mv <- lm(univ_GPA ~ math_SAT + verb_SAT, data=ddf)
summary(r.mv)
## 
## Call:
## lm(formula = univ_GPA ~ math_SAT + verb_SAT, data = ddf)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.7808 -0.1844  0.0568  0.2054  0.7499 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)   
## (Intercept) -0.2375336  0.3750378  -0.633  0.52792   
## math_SAT     0.0032909  0.0010902   3.019  0.00321 **
## verb_SAT     0.0022718  0.0009308   2.441  0.01638 * 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3287 on 102 degrees of freedom
## Multiple R-squared:  0.4702, Adjusted R-squared:  0.4598 
## F-statistic: 45.27 on 2 and 102 DF,  p-value: 8.488e-15
# we add interaction
r.mv.i <- lm(univ_GPA ~ math_SAT + verb_SAT + math_SAT * verb_SAT, data=ddf)
# or shorter
r.mv.i <- lm(univ_GPA ~ math_SAT * verb_SAT, data=ddf)
summary(r.mv.i)
## 
## Call:
## lm(formula = univ_GPA ~ math_SAT * verb_SAT, data = ddf)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.85523 -0.18050  0.03869  0.18225  0.93201 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)   
## (Intercept)       -1.088e+01  4.015e+00  -2.711  0.00788 **
## math_SAT           2.030e-02  6.475e-03   3.135  0.00225 **
## verb_SAT           2.002e-02  6.725e-03   2.976  0.00365 **
## math_SAT:verb_SAT -2.814e-05  1.057e-05  -2.663  0.00902 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3193 on 101 degrees of freedom
## Multiple R-squared:  0.505,  Adjusted R-squared:  0.4903 
## F-statistic: 34.34 on 3 and 101 DF,  p-value: 2.196e-15

do the same using multi level models

ddf <- read.delim("http://md.psych.bio.uni-goettingen.de/data/div/sat.txt")
names_ddf <- names(ddf)
# we add a subject number
ddf <- cbind(1:length(ddf$high_GPA), ddf)
names(ddf) <- c('subj', names_ddf)

require(nlme)
## Loading required package: nlme
r.0 <- lme(fixed = univ_GPA ~ 1, random = ~ 1 | subj, data=ddf, method='ML')
r.m <- lme(fixed = univ_GPA ~ 1 + math_SAT, random = ~ 1 | subj, data=ddf, method='ML')
r.v <- lme(fixed = univ_GPA ~ 1 + verb_SAT, random = ~ 1 | subj, data=ddf, method='ML')
r.mv  <- lme(fixed = univ_GPA ~ 1 + math_SAT + verb_SAT, random = ~ 1 | subj, data=ddf, method='ML')

anova(r.0, r.m)
##     Model df      AIC       BIC    logLik   Test  L.Ratio p-value
## r.0     1  3 133.9719 141.93382 -63.98597                        
## r.m     2  4  75.2255  85.84134 -33.61275 1 vs 2 60.74645  <.0001
anova(r.0, r.v)
##     Model df       AIC       BIC    logLik   Test  L.Ratio p-value
## r.0     1  3 133.97194 141.93382 -63.98597                        
## r.v     2  4  78.25079  88.86663 -35.12539 1 vs 2 57.72115  <.0001
anova(r.0, r.mv)
##      Model df       AIC       BIC    logLik   Test  L.Ratio p-value
## r.0      1  3 133.97194 141.93382 -63.98597                        
## r.mv     2  5  71.26579  84.53559 -30.63289 1 vs 2 66.70616  <.0001
anova(r.0, r.m, r.mv)
##      Model df       AIC       BIC    logLik   Test  L.Ratio p-value
## r.0      1  3 133.97194 141.93382 -63.98597                        
## r.m      2  4  75.22550  85.84134 -33.61275 1 vs 2 60.74645  <.0001
## r.mv     3  5  71.26579  84.53559 -30.63289 2 vs 3  5.95971  0.0146
anova(r.0, r.v, r.mv)
##      Model df       AIC       BIC    logLik   Test  L.Ratio p-value
## r.0      1  3 133.97194 141.93382 -63.98597                        
## r.v      2  4  78.25079  88.86663 -35.12539 1 vs 2 57.72115  <.0001
## r.mv     3  5  71.26579  84.53559 -30.63289 2 vs 3  8.98500  0.0027
# ... we can clearly see the increase of predictive power

summary(r.0)
## Linear mixed-effects model fit by maximum likelihood
##  Data: ddf 
##        AIC      BIC    logLik
##   133.9719 141.9338 -63.98597
## 
## Random effects:
##  Formula: ~1 | subj
##         (Intercept)  Residual
## StdDev:   0.4167218 0.1562707
## 
## Fixed effects: univ_GPA ~ 1 
##                Value  Std.Error  DF  t-value p-value
## (Intercept) 3.172857 0.04364163 105 72.70254       0
## 
## Standardized Within-Group Residuals:
##         Min          Q1         Med          Q3         Max 
## -0.86219518 -0.12848399  0.09241831  0.23442692  0.50266543 
## 
## Number of Observations: 105
## Number of Groups: 105
summary(r.m)
## Linear mixed-effects model fit by maximum likelihood
##  Data: ddf 
##       AIC      BIC    logLik
##   75.2255 85.84134 -33.61275
## 
## Random effects:
##  Formula: ~1 | subj
##         (Intercept)  Residual
## StdDev:   0.3120458 0.1170172
## 
## Fixed effects: univ_GPA ~ 1 + math_SAT 
##                   Value Std.Error  DF   t-value p-value
## (Intercept) -0.26229241 0.3838157 103 -0.683381  0.4959
## math_SAT     0.00551321 0.0006137 103  8.982935  0.0000
##  Correlation: 
##          (Intr)
## math_SAT -0.996
## 
## Standardized Within-Group Residuals:
##         Min          Q1         Med          Q3         Max 
## -0.83150129 -0.24937333  0.02066688  0.25001464  0.87181756 
## 
## Number of Observations: 105
## Number of Groups: 105
summary(r.mv)
## Linear mixed-effects model fit by maximum likelihood
##  Data: ddf 
##        AIC      BIC    logLik
##   71.26579 84.53559 -30.63289
## 
## Random effects:
##  Formula: ~1 | subj
##         (Intercept) Residual
## StdDev:   0.3033146 0.113743
## 
## Fixed effects: univ_GPA ~ 1 + math_SAT + verb_SAT 
##                   Value Std.Error  DF    t-value p-value
## (Intercept) -0.23753363 0.3750378 102 -0.6333591  0.5279
## math_SAT     0.00329089 0.0010902 102  3.0187112  0.0032
## verb_SAT     0.00227183 0.0009308 102  2.4406735  0.0164
##  Correlation: 
##          (Intr) mt_SAT
## math_SAT -0.570       
## verb_SAT  0.027 -0.835
## 
## Standardized Within-Group Residuals:
##         Min          Q1         Med          Q3         Max 
## -0.84626669 -0.19981903  0.06156895  0.22259382  0.81283833 
## 
## Number of Observations: 105
## Number of Groups: 105

Explizite Schätzung der Parameter via mle2() aus bbmle()

ddf <- read.delim("http://md.psych.bio.uni-goettingen.de/data/div/sat.txt")
names_ddf <- names(ddf)
# we add a subject number
ddf <- cbind(1:length(ddf$high_GPA), ddf)
names(ddf) <- c('subj', names_ddf)

# bbmle offers mle2()
require(bbmle)
## Loading required package: bbmle
## Loading required package: stats4
# define function for log likelihood
ll2 = function(params){
  # we could want to inspect the varying parameters when optimizing
  # print(params)
  # we create a matrix of one col, rows is n of parameters but sigma (sd residuals i.e. of unexplained variability Epsilon, mean is 0 by default)
  beta = matrix(NA, nrow = length(params) - 1, ncol = 1)
  beta[,1] = params[-length(params)]  # sigma is excluded 
  sigma    = params[[length(params)]] # sd of residuals
  # the model predictives are subtracted from response variable and these differences (residuals) are normally distributed with mean=0
  minusll  = -sum(log(dnorm(Y - X %*% beta, 0, sigma)))
  # X is model.matrix. Model matrix matrix-multiplied with vector of weights (parameters) is the linear model
  return(minusll)
}

Y <- ddf$univ_GPA
X <- model.matrix(lm(univ_GPA ~ verb_SAT, data = ddf))

# REGRESS Y ON X1
X <- model.matrix(lm(univ_GPA ~ verb_SAT, data = ddf))
parnames(ll2) <- c('beta0', 'beta1', 'sigma')
m1 <- mle2(ll2, start = c(beta0 = 0, beta1 = 0, sigma = 1), vecpar = TRUE)
## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt
# REGRESS Y ON X1 + X2

X <- model.matrix(lm(univ_GPA ~ verb_SAT + math_SAT, data = ddf))
parnames(ll2) <- c('beta0', 'beta1', 'beta2', 'sigma')
m2 <- mle2(ll2, start = c(beta0 = 0, beta1 = 0, beta2 = 0, sigma = 1), vecpar = TRUE)
## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt
# compare models
AICctab(m1,m2, nobs=length(ddf$subj), sort=TRUE, delta=TRUE, weights=TRUE)
##    dAICc df weight
## m2 0.0   4  0.968 
## m1 6.8   3  0.032
# ... probability of m2 to be "the best model"" is much higher than for m1

# chi^2 test of the model difference
anova(m1, m2)
## Likelihood Ratio Tests
## Model 1: m1, [ll2]: beta0+beta1+sigma
## Model 2: m2, [ll2]: beta0+beta1+beta2+sigma
##   Tot Df Deviance Chisq Df Pr(>Chisq)   
## 1      3   70.251                       
## 2      4   61.266 8.985  1   0.002722 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# ... the explanatory power of model m2 is significantly better than of model m1
# ... model fit of m2 is significantly better than model fit of m1

Tests only

# bbmle offers mle2()
require(bbmle)

n <- 100
df <- data.frame(x1 = runif(n), x2 = runif(n), y = runif(n))
Y <- df$y
X <- model.matrix(lm(y ~ x1, data = df))

# REDEFINE LOG LIKELIHOOD
ll2 = function(params){
  # we could want to inspect the varying parameters when optimizing
  # print(params)
  # we create a matrix of one col, rows is n of parameters but sigma (sd residuals i.e. of unexplained variability Epsilon, mean is 0 by default)
  beta = matrix(NA, nrow = length(params) - 1, ncol = 1)
  beta[,1] = params[-length(params)]  # sigma is excluded 
  sigma    = params[[length(params)]] # sd of residuals
  # the model predictives are subtracted from response variable and these differences (residuals) are normally distributed with mean=0
  minusll  = -sum(log(dnorm(Y - X %*% beta, 0, sigma)))
  # X is model.matrix. Model matrix matrix-multiplied with vector of weights (parameters) is the linear model
  return(minusll)
}

# REGRESS Y ON X1
X <- model.matrix(lm(y ~ x1, data = df))
parnames(ll2) <- c('beta0', 'beta1', 'sigma')
#mle2(ll2, start = c(beta0 = 0.1, beta1 = 0.2, sigma = 1), vecpar = TRUE, parnames = c('beta0', 'beta1', 'sigma'))
m1 <- mle2(ll2, start = c(beta0 = 0.1, beta1 = 0.2, sigma = 1), vecpar = TRUE)
## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt
# REGRESS Y ON X1 + X2

X <- model.matrix(lm(y ~ x1 + x2, data = df))
parnames(ll2) <- c('beta0', 'beta1', 'beta2', 'sigma')
m2 <- mle2(ll2, start = c(beta0 = 0.1, beta1 = 0.2, beta2 = 0.1, sigma = 1), vecpar = TRUE, parnames = c('beta0', 'beta1', 'beta2', 'sigma'))
## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt

## Warning in dnorm(Y - X %*% beta, 0, sigma): NaNs wurden erzeugt
# compare models
AICctab(m1,m2, nobs=100, sort=TRUE, delta=TRUE, weights=TRUE)
##    dAICc df weight
## m1 0.0   3  0.66  
## m2 1.3   4  0.34

Explanation of Akaike’s weights, what it is and what it is good for.

Tests 2

#Imagine we sample the nutrient content in an experimental tank ten times 
#across an afternoon.  We get the following results:
nut <- c(56.3, 50.6, 49.5, 57.8, 71.4, 50., 61.3, 60.7, 77.7, 70.4)
plot(nut)

#Assume there is no fundamental difference among the samples.  Find the average.

#We will assume there is obervational error with each sampling.
#Since these nutrient concentrations are continous numbers, we will assume
#that the observational error is simply normal or Gaussian

#1) simulate the data

#first, I'll draw the pdf with a guess for the mean and stdev
curve(dnorm(x,50.0,6.0),30,70)

simData <- rnorm(10,50.0,6.0)
plot(simData)

#we could guess and check to find an acceptable mean and standard deviation
#instead, we'll use maximum likelihood to find the best estimates

#In the simulation we use the probability density function to tell us the
#probability.  We can work backwards, using the same equation to find the
#likelihood of the parameters, given the data.  For example, take the probability
#density function (pdf) of the normal distribution from above.  If we say the
#m = 5.3, and s = 1.2, the pdf will tell us the probability density of getting 6.2 
#were we to randomly draw from the distribution.

dnorm(6.2,5.3,1.2)
## [1] 0.2509479
curve(dnorm(x,5.3,1.2),1,9)

#We can turn that around and ask, "What is the likelihood of the mean being 5.3
#if a draw from the distribution resulted in 6.2?"  For right now, let us assume
#we know the standard deviation is 1.2.  The likelihood is actually proportional
#to the probability.  Since we will be concerned with relative likelihood, we will
#ignore the proportionality constant and assume they are equal.

dnorm(6.2,5.3,1.2)
## [1] 0.2509479
#The number is actually the same, even the though the philosophy is the reverse.

#This time plot the likelihood across a range of m, because the data is fixed this
#time at 6.2

curve(dnorm(6.2,x,1.2),1,10)

#Where is the maximum likelihood?  Given a single value of 6.2, it is most likely
#that the mean is 6.2.  Your plot should peak at 6.2.

#In order to easily manipulate likelihood values, we transform the likelihood by
#taking the -log().  Negative log-likelihood values have the nice property that
#they can be summed across multiple events.  The other twist, is that you minimize
#the negative log-likelihood in order to find the maximum likelihood.

#This negative log-likelihood is called the support function because it is used to
#find support for the parameters, given the data.

sf <- function (z,m,s)
-dnorm(z,m,s,log = TRUE)

curve(sf(6.2,x,1.2),0,10)

sf(nut,60,3)
##  [1]  2.778106  6.926440  8.142551  2.286440  9.237551  7.573106  2.111440
##  [8]  2.044773 19.422551  8.026440
sum(sf(nut,60,3))
## [1] 68.5494
#create a single function for the negative log-likelihood of the data set
ll <- function (m,s)
-sum(dnorm(nut,m,s,log = TRUE))

library(bbmle)
#-# source("mleFunctions.R")

guess <- list(m = 60.0, s = 3.0)
fit <- mle2(ll, start=guess, method="Nelder-Mead")
fit
## 
## Call:
## mle2(minuslogl = ll, start = guess, method = "Nelder-Mead")
## 
## Coefficients:
##         m         s 
## 60.571805  9.313474 
## 
## Log-likelihood: -36.5
-logLik(fit)
## 'log Lik.' 36.50443 (df=2)
mean(nut)
## [1] 60.57
#-# comp <- compare(fit, name = "constant")

#redo analysis and include the time each data point was collected
time = c(2.3,2.6,3,3.1,3.3,3.4,3.4,4.1,4.6,4.8)
ponds <- data.frame(list("time" = time, "nutrients" = nut))
plot(ponds)

ll <- function (m1,m2,s) with(ponds,
-sum(dnorm(nutrients,m1+m2*time,s,log = TRUE)))
guess <- list(m1 = 60.0, m2 = 2.3, s = 3.0)
fit <- mle2(ll, start=guess, method="Nelder-Mead")

fit
## 
## Call:
## mle2(minuslogl = ll, start = guess, method = "Nelder-Mead")
## 
## Coefficients:
##        m1        m2         s 
## 30.833437  8.594580  6.531963 
## 
## Log-likelihood: -32.96
-logLik(fit)
## 'log Lik.' 32.95969 (df=3)
#-# comp <- compare(fit, name = "linear", prev = comp)
#-# comp

#-# compare.likRatio(comp,1,2)

Hintergrund Notensystem USA

Grade Point Average (GPA) GPA-The Basics A GPA (which is an acronym for grade point average) is the calculated average of the grades you earn. The scale follows a 0 to 4.0 or 5.0 scale. Each semester, you earn a GPA based on your grades from that semester. Throughout the duration of your high school career, you’ll earn a cumulative GPA. The cumulative GPA is an ongoing average which represents your average based on each semester that you’ve completed. In order to determine what type of GPA you need to earn in order to gain admittance to a college, it’s a good idea to know what the average GPA for acceptance is. While many colleges accept a GPA of 3.0 from freshmen and transfer students, they will oftentimes consider applicants with lower grades. On a national level, maintaining a B average has become somewhat standard. As you climb the college ladder in terms of selectivity, you will note that the more competitive institutions expect applicants to have at least a B as their minimum GPA. These institutions will also be analyzing the applications of students who have earned B+, A–, and A averages.

SAT Requirements For College In addition to analyzing a student’s GPA when determining whether she or he will gain admittance to an educational institution, the admissions office will consider the student’s ACT scores. In order to be considered “elite” or “highly selective,” a college must keep its SAT numbers high. With that idea in mind, it’s important to understand what the SAT consists of while also grasping what type of score colleges consider to be competitive. The SAT exam is comprised of three components: Critical Reading, Mathematics, and Writing. SAT scores for each component of the exam will range from 200-800, meaning that the highest score one can attain is 2400. Studies indicate that the average score for every component of the exam is about 500, making the total average score around 1500. In gauging the results of the 1.66 million tests taken in 2013, results indicated that the average scores were 488 for writing, 514 for math, and 496 for critical reading. Below you will find a list of schools including the middle range of SAT scores that they accept. This means that 50% of the individuals accepted into these institutions earned an SAT score falling within the range listed. In analyzing the list, note that 25% of the students admitted to the colleges scored lower than the middle range listed. In some cases, the writing scores are not listed. This omission results from the fact that the writing component of the test is still relatively new, and several institutions do not consider it when evaluating applications.

Deutsche Noten im amerikanischen Schulsystem Notensystem USA Notensystem Deutschland

Letter Grade GPA Note Beschreibung
A+ 1.0
A 4.0 1.0 Sehr gut
A- 3.7 1.3
B+ 3.3 1.7
B 3.0 2.0 Gut
B- 2.7 2.3
C+ 2.3 2.7
C 2.0 3.0 Befriedigend
C- 1.7 3.3
D+ 1.3 3.7
D 1.0 4.0 Ausreichend
F 0.0 5.0 Nicht ausreichend

Was ist der Grade Point Average (GPA)? Amerikanische Schüler bekommen ihre Noten nicht wie bei uns in Zahlen von 1 bis 6, sondern in Buchstaben von A bis F. Das „A“ entspricht dabei unser deutschen „1“ und ist somit die beste Note, das amerikanische „F“ hingegen entspricht der deutschen „6“. Damit man trotzdem eine Art Notendurchschnitt angeben kann, gibt es den Grade Point Average, den GPA. Mit ihm überprüfen US-amerikanische Firmen und Universitäten, ob der Notendurchschnitt ausländischer Bewerber ihren Anforderungen entspricht. Aber auch für Deinen Schüleraustausch in den USA kann der GPA spannend sein. Wenn Du Deinen deutschen Notendurchschnitt umrechnen möchtest, hilft Dir unsere Tabelle. Beachte, dass dies nur die ungefähren Werte sind. Die Anerkennung von ausländischen Noten kann von Schule zu Schule variieren, in der Regel fällt die Bewertung aber wie angegeben aus. Ob der Wert überhaupt benötigt wird, liegt bei den einzelnen Schulen. In der Regel kennen sich die Schulen, die internationale Schüler aufnehmen, aber auch mit ausländischen Notensystemen aus und Du wirst den Wert nicht selber ausrechnen müssen, sondern nur Deinen deutschen Notendurchschnitt angeben. Auch in unseren Bewerbungsunterlagen sind lediglich Deine deutschen Noten interessant.

SAT

Der SAT (Abkürzung ohne Bedeutung, ehemals Scholastic Assessment Test, davor Scholastic Aptitude Test und davor Scholastic Achievement Test) ist ein US-amerikanischer standardisierter Test, der hauptsächlich von Studienplatzbewerbern an amerikanischen Universitäten gefordert wird (Studierfähigkeitstest).

Da das Schulsystem der USA sehr uneinheitlich ist, sind Schulnoten verschiedener High Schools im Allgemeinen nicht miteinander vergleichbar. Daher führt das College Board, eine Vereinigung 4.500 amerikanischer Bildungseinrichtungen, an landesweit gleichzeitigen Terminen standardisierte Tests durch, deren Ergebnisse oftmals über den weiteren Bildungsweg eines Schülers entscheiden.

Jeder Test besteht aus mehreren Modulen: Einem allgemeinen Teil, der sich in die Abschnitte Mathematik, kritisches Lesen und kreatives Schreiben gliedert, und bis zu drei fachspezifischen Tests, von denen insgesamt 20 zur Auswahl stehen. Die Tests erfolgen vorwiegend nach dem Multiple-Choice-Verfahren. Jeder Teiltest wird mit einer Punktzahl zwischen 200 und 800 bewertet, die anschließend wegen unterschiedlicher Schwierigkeitsgrade skaliert wird, um auch zwischen verschiedenen SAT-Tests vergleichbare Ergebnisse zu erhalten.

Der SAT wurde seit seiner Einführung 1901 mehrfach grundlegend überarbeitet und umbenannt. Dabei versuchte man stets, dem Ziel des Tests, kein Wissen, sondern Fähigkeiten zu ermitteln, näher zu kommen und Benachteiligungen von Probanden aus ärmeren Schulbezirken zu vermeiden.

Mit dem SAT lassen sich die Erfolge des Highschool-Systems messen, mit dem High School Diploma auch die akademischen Voraussetzungen für den Besuch eines Colleges zu erreichen. Seit 2009 erreichten dabei in den Vereinigten Staaten weniger als die Hälfte der Highschool-Absolventen den Schwellenwert von 1550 Punkten im SAT (Stand einschließlich der Daten von 2013).[1] Der Bildungsgrad der Eltern sagte 2013 den Erfolg der Kinder am besten voraus: Während 68 % der Kinder den Schwellenwert erreichten, von denen mindestens ein Elternteil einen Master- oder höheren Abschluss hatten, schafften das nur 27 % der Kinder, deren Eltern nur einen Highschool-Abschluss hatten. Zweitwichtigster Faktor war die Rasse nach der Definition der US-Bevölkerungsstatistik: Schüler asiatischer Herkunft erreichten den Grenzwert zu 56 %, weiße zu 53 %, indigene Amerikaner 35 %, Hispanics zu 24 % und Schwarze zu 15 %.[2]

Auch einige private Hochschulen in Deutschland, wie die Jacobs University Bremen oder die inzwischen nach Insolvenz aufgelöste International University in Germany in Bruchsal, forderten von Bewerbern das Ablegen des Tests.

Aufgaben auf Original-Website

Exercises

  1. Draw a scatterplot comparing the students’ high school GPAs to their overall university GPAs. What does the relationship appear to be? (4.1)

  2. What is the correlation between high school GPA and overall university GPA? (4.5)

  3. Find the regression line for predicting the overall university GPA from the high school GPA.
    • What is the slope?
    • What is the y-intercept?
    • If someone had a 2.2 GPA in high school, what is the best estimate of his or her college GPA?
    • If someone had a 4.0 GPA in high school, what is the best estimate of his or her college GPA?
  4. What is the mean math and verbal SAT score in this sample? (3.2)
  5. What are the standard deviations of the math and verbal SAT scores? (3.10)
  6. What would you expect the correlation between math and verbal SAT scores to be? Now calculate this correlation. (4.2, 4.5)
  7. What is the correlation between the students’ overall university GPAs and their computer science GPAs? (4.5)
  8. Did the students have higher overall GPAs or higher GPAs in their computer science classes?
    • Calculate each of these means. (3.2)
    • Conduct a paired t test to see if this difference is statistically significant. (10.6)
  9. Find the regression line for predicting the overall university GPA from both the math SAT score and the verbal SAT score.
    • Write out the regression equation to calculate GPA. Note the coefficients and the constant.
    • What is the R square of the model?
    • What is the p value for the coefficient of each SAT score? Are they both significant at the .05 level?
    • What would you predict someone’s overall university GPA to be if she got a 600 on the math and a 540 on the verbal portion of the SAT?