{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [], "authorship_tag": "ABX9TyN8ajHLr6msiSzoIcTuHssU", "include_colab_link": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 81 }, "id": "YdU8K3UyBdOX", "outputId": "c98961ab-654d-43ad-f534-f2656a168a7f" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " Degree of freedom 1 Degree of freedom 2 F-statistic p-value\n", "0 8 29 0.251063 0.023463" ], "text/html": [ "\n", "
\n", "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Degree of freedom 1Degree of freedom 2F-statisticp-value
08290.2510630.023463
\n", "
\n", "
\n", "\n", "
\n", " \n", "\n", " \n", "\n", " \n", "
\n", "\n", "
\n", "
\n" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "dataframe", "summary": "{\n \"name\": \"pd\",\n \"rows\": 1,\n \"fields\": [\n {\n \"column\": \"Degree of freedom 1\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": null,\n \"min\": 8,\n \"max\": 8,\n \"num_unique_values\": 1,\n \"samples\": [\n 8\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Degree of freedom 2\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": null,\n \"min\": 29,\n \"max\": 29,\n \"num_unique_values\": 1,\n \"samples\": [\n 29\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"F-statistic\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": null,\n \"min\": 0.25106326202802354,\n \"max\": 0.25106326202802354,\n \"num_unique_values\": 1,\n \"samples\": [\n 0.25106326202802354\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"p-value\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": null,\n \"min\": 0.023462662623980567,\n \"max\": 0.023462662623980567,\n \"num_unique_values\": 1,\n \"samples\": [\n 0.023462662623980567\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}" } }, "metadata": {}, "execution_count": 1 } ], "source": [ "import numpy as np\n", "import pandas as pd\n", "import scipy.stats as stats\n", "\n", "# Create synthetic data for testing.\n", "group1 = np.random.normal(0.0, 1.0, size=9)\n", "group2 = np.random.normal(10.0, 2.0, size=30)\n", "\n", "# Calculate the F-statistic.\n", "variance1 = np.var(group1, ddof=1)\n", "variance2 = np.var(group2, ddof=1)\n", "f_value = variance1 / variance2\n", "\n", "# Calculate the p-value.\n", "df1 = len(group1) - 1\n", "df2 = len(group2) - 1\n", "p_value = stats.f.cdf(f_value, df1, df2)\n", "\n", "# Collect results.\n", "scores = {\n", " \"Degree of freedom 1\": df1,\n", " \"Degree of freedom 2\": df2,\n", " \"F-statistic\": f_value,\n", " \"p-value\": p_value,\n", "}\n", "pd.DataFrame(scores, index=[0])" ] } ] }