Lead Exposure and Behavior

Researchers investigated whether exposure to lead affected the behavior in poor children between the ages of 1 and 3 years old. The researchers measured the blood lead level of each child in the study. Children with blood lead levels between 0 and 0.48 µmol/L were classified as “Nonexposed,” and those with lead levels between 0.48 and 1.20 µmol/L were classified as “Exposed.” Other researchers gave the children a behavior assessment, called the Behavior Rating Scale (BRS). The scores on the BRS are percentiles. Higher numbers are more desirable, since they indicate fewer problematic behaviors.
MATH221
health
environmentalhealth
behavioralscience
Author

MATH 221

Published

April 30, 2024

Data details

There are 72 rows and 5 columns. The data source1 is used to create our data that is stored in our pins table. You can access this pin from a connection to posit.byui.edu using hathawayj/lead_exposure_and_behavior.

This data is available to all.

Variable description

  • Group: Subject group based on lead exposure (Nonexposed, Exposed)
  • Gender: Gender (M, F)
  • Age: Age (months)
  • Lead: Concentration of lead in blood (micromoles per liter)
  • BRS: Score from Behavior Rating Scale (BRS), in percentiles: higher numbers indicate less problematic behavior

Variable summary

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
Age 0 1 23.25 6.69 12.2 17.75 22.70 27.60 35.80 ▆▇▇▅▅
Lead 0 1 0.50 0.29 0.0 0.27 0.52 0.63 1.18 ▆▅▇▃▂
BRS 0 1 53.72 28.99 1.0 32.25 55.50 76.00 99.00 ▆▆▆▇▇

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
Group 0 1 7 10 0 2 0
Gender 0 1 1 1 0 2 0
Explore generating code using R
library(tidyverse)
library(pins)
library(connectapi)

lead_exposure_and_behavior <- read_csv('https://github.com/byuistats/data/raw/master/LeadExposureAndBehavior/LeadExposureAndBehavior.csv')


# Publish the data to the server with Bro. Hathaway as the owner.
board <- board_connect()
pin_write(board, lead_exposure_and_behavior, type = "parquet", access_type = "all")

pin_name <- "lead_exposure_and_behavior"
meta <- pin_meta(board, paste0("hathawayj/", pin_name))
client <- connect()
my_app <- content_item(client, meta$local$content_id)
set_vanity_url(my_app, paste0("data/", pin_name))

Access data

This data is available to all.

Direct Download: lead_exposure_and_behavior.parquet

R and Python Download:

URL Connections:

For public data, any user can connect and read the data using pins::board_connect_url() in R.

library(pins)
url_data <- "https://posit.byui.edu/data/lead_exposure_and_behavior/"
board_url <- board_connect_url(c("dat" = url_data))
dat <- pin_read(board_url, "dat")

Use this custom function in Python to have the data in a Pandas DataFrame.

import pandas as pd
import requests
from io import BytesIO

def read_url_pin(name):
  url = "https://posit.byui.edu/data/" + name + "/" + name + ".parquet"
  response = requests.get(url)
  if response.status_code == 200:
    parquet_content = BytesIO(response.content)
    pandas_dataframe = pd.read_parquet(parquet_content)
    return pandas_dataframe
  else:
    print(f"Failed to retrieve data. Status code: {response.status_code}")
    return None

# Example usage:
pandas_df = read_url_pin("lead_exposure_and_behavior")

Authenticated Connection:

Our connect server is https://posit.byui.edu which you assign to your CONNECT_SERVER environment variable. You must create an API key and store it in your environment under CONNECT_API_KEY.

Read more about environment variables and the pins package to understand how these environment variables are stored and accessed in R and Python with pins.

library(pins)
board <- board_connect(auth = "auto")
dat <- pin_read(board, "hathawayj/lead_exposure_and_behavior")
import os
from pins import board_rsconnect
from dotenv import load_dotenv
load_dotenv()
API_KEY = os.getenv('CONNECT_API_KEY')
SERVER = os.getenv('CONNECT_SERVER')

board = board_rsconnect(server_url=SERVER, api_key=API_KEY)
dat = board.pin_read("hathawayj/lead_exposure_and_behavior")