<commit_before>---
layout: post
title: "Using the delta method"
description: ""
category: R
tags: [R, delta method, stats, statsblogs]
---
{% include JB/setup %}

_This was originally posted at [Point Mass Prior](http://dasonk.github.com) and features MathML.  If you're viewing from StatsBlogs the math probably won't show up properly and it would be beneficial to view the post [here]({{ page.url }})_

Somebody recently asked me about the delta method and specifically the `deltamethod` function in the msm package.  I thought I would write about that and so to motivate this we'll look at an example.  The example we'll consider is a simple case where we fit a quadratic regression to some data.  This means our model has the form

$$y_i = \beta_0 + \beta_1x_i + \beta_2x_i^2 + \epsilon_i$$

where $$\epsilon_i$$ are independent and identically distributed normal random variables with mean 0 and a variance of $$\sigma^2$$.

To start we'll generate some data such that we have roots at x=0 and x=10 and the quadratic is such that we have a maximum instead of a minimum.


{% highlight r %}
set.seed(500)
n <- 30
x <- runif(n, 0, 10)<commit_msg>Added rbloggers<commit_after>---
layout: post
title: "Using the delta method"
description: ""
category: R
tags: [R, delta method, stats, statsblogs, rbloggers]
---
{% include JB/setup %}

_This was originally posted at [Point Mass Prior](http://dasonk.github.com) and features MathML.  If you're viewing from StatsBlogs the math probably won't show up properly and it would be beneficial to view the post [here]({{ page.url }})_

Somebody recently asked me about the delta method and specifically the `deltamethod` function in the msm package.  I thought I would write about that and so to motivate this we'll look at an example.  The example we'll consider is a simple case where we fit a quadratic regression to some data.  This means our model has the form

$$y_i = \beta_0 + \beta_1x_i + \beta_2x_i^2 + \epsilon_i$$

where $$\epsilon_i$$ are independent and identically distributed normal random variables with mean 0 and a variance of $$\sigma^2$$.

To start we'll generate some data such that we have roots at x=0 and x=10 and the quadratic is such that we have a maximum instead of a minimum.


{% highlight r %}
set.seed(500)
n <- 30
x <- runif(n, 0, 10)
{'fraction_non_alphanumeric': 0.08697533535266118, 'fraction_numerical': 0.014712245781047165, 'mean_word_length': 4.172259507829978, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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}}
{'dir': 'git-commits-cleaned', 'id': '5097039', 'n_tokens_mistral': 710, 'n_tokens_neox': 648, 'n_words': 345}