Monday, December 12, 2022

What I learned today: Continuous scales and Discrete scales

I am doing this Google Playstore analysis. After the cleaning part that took me about 2 days, I am now to the visualization of the results.

So a lot og ggplot. graphs with 1 variable, with 2 and now with 3. In this procedure I am learning through my mistakes. Which are many... But anyway, I keep the good part: I am learning something new, in every mistake I meet. And today I am learning about the 2 kind of scales: Continuous and Discrete. So lets explore the terms:

In ggplot, a scale is like a rule that tells the computer how to draw a graph. There are two types of scales: continuous scales and discrete scales.

A continuous scale is used when the data has numbers that can be any value within a range. For example, if you have a column of data that shows how tall people are, you would use a continuous scale to draw a line on the graph that shows how the height of the people changes.

A discrete scale is used when the data has values that are specific, rather than any value within a range. For example, if you have a column of data that shows the favorite color of different people, you would use a discrete scale to draw a bar graph that shows how many people like each color.

Overall, scales help the computer understand how to draw a graph and show the data in a clear way.

Friday, December 9, 2022

Asking the right questions

 

Something that I find very difficult at least now in the beginning of this journey is how to find the right questions to ask, so I can have results, in a dataset. asking the right questions when analyzing a dataset is crucial for gaining insights and understanding the data: Trying to follow these guidelines:

  • Start with the basics: What are the columns in the dataset and what do they represent? What is the format and type of data in each column? What are the dimensions of the dataset (number of rows and columns)?
  • Identify the research question or problem you are trying to solve: What do you want to learn from the dataset? What information do you need to answer your research question or solve your problem?
  • Identify the relevant variables and their relationships: Which columns in the dataset are relevant to your research question or problem? How are these variables related to each other and to the outcome you are trying to predict or explain?
  • Explore the data and look for patterns and trends: What are the patterns and trends in the data? Are there any outliers or anomalies that need to be addressed? Are there any missing or incomplete values in the data?
  • Ask specific and focused questions: What do you want to know about the data? What are the key variables and relationships you want to investigate? How will you measure and analyze the data to answer your questions?


Thursday, December 8, 2022

Analyze more


(alpha and p values for data analytics)




The alpha and p values are used in statistics to help us understand if our results are reliable. The alpha value is like a cutoff point – it's the level of confidence that we want to have in our results. For example, if we set the alpha value to 0.05, it means that we are confident that our results are correct 95% of the time.


The p value is the probability that we would get our results just by chance, even if the thing we're testing (called the null hypothesis) isn't true. So if we're testing whether boys are taller than girls on average, and we get a p value of 0.01, that means there's only a 1% chance that we would see a difference in height just by chance, even if boys and girls are actually the same height on average.


If the p value is less than the alpha value, we can say that our results are reliable and that the null hypothesis is probably not true. So in the example above, if the alpha value is 0.05 and the p value is 0.01, we can say that boys are probably taller than girls on average because it's unlikely that we would see a difference in height just by chance.


Alpha and p values help us decide if our results are reliable and if we can trust them to tell us something about the world. The alpha value is the level of confidence that we want to have in our results, and the p value is the probability that we would see our results just by chance. If the p value is less than the alpha value, we can say that our results are reliable and that the null hypothesis is probably not true.

2. Regression analysis

Regression analysis is a statistical method used to understand the relationship between two or more variables. It allows us to examine the strength and direction of the relationship between the variables, and to make predictions about the values of one variable based on the values of the other variables.

For example, let's say we want to understand the relationship between the amount of time that people spend exercising and their weight. We could use regression analysis to analyze data from a sample of people, looking at their exercise habits and their weight. The regression analysis would allow us to see if there is a relationship between exercise and weight, and if there is, how strong the relationship is. We could then use this information to make predictions about how changes in exercise habits might affect weight.

1. Descriptive statistics


Descriptive statistics are a set of techniques used to summarize and describe the characteristics of a dataset. Some common descriptive statistics include:

  • Mean: The arithmetic average of a set of numbers, calculated by adding up all the numbers and dividing by the number of numbers.
  • Median: The middle value in a set of numbers, when the numbers are arranged in order from smallest to largest.
  • Mode: The most frequently occurring value in a set of numbers.
  • Range: The difference between the largest and smallest values in a set of numbers.
  • Standard deviation: A measure of how spread out the values in a dataset are, calculated by taking the square root of the average of the squared differences between each value and the mean.

In R, you can use the summary() function to calculate these descriptive statistics for numeric data. For example, the following code uses the summary() function to calculate the mean, median, mode, range, and standard deviation for the "x" vector:

x <- c(1, 2, 3, 4, 5)

summary(x)

The output of the summary() function shows the mean, median, mode, range, and standard deviation for the "x" vector, as shown below:

Min. 1st Qu. Median Mean 3rd Qu. Max.

1.00 2.25 3.00 3.00 3.75 5.00

In this example, the mean of the "x" vector is 3.00, the median is 3.00, the mode is NA (there is no most frequently occurring value), the range is 4 (5 - 1), and the standard deviation is 1.581.

Descriptive statistics are useful tools for summarizing and describing the characteristics of a dataset. The summary() function in R is a convenient way to calculate common descriptive statistics such as mean, median, mode, range, and standard deviation.

An example:

a real case study in r using Descriptive statistics

A real-world example of using descriptive statistics in R is analyzing the salary data for a company. The following code uses the summary() function to calculate the mean, median, mode, range, and standard deviation for the salary data:

library(dplyr)

salary_data <- read.csv("salary_data.csv")

summary(salary_data$salary)

The output of the summary() function shows the mean, median, mode, range, and standard deviation for the salary data, as shown below:


Min. 1st Qu. Median Mean 3rd Qu. Max.

45000.0 55000.0 65000.0 65712.5 75000.0 85000.0

In this example, the mean salary is $65,712.50, the median salary is $65,000.00, the mode salary is NA (there is no most frequently occurring salary), the range of salaries is $40,000.00 ($85,000.00 - $45,000.00), and the standard deviation of salaries is $10,098.99.

These descriptive statistics can help the company understand the characteristics of their salary data, such as the average salary and the spread of salaries within the company. The company can use this information to make informed decisions about salary increases and salary ranges for different job positions.


Analyze data in R


There are several ways to analyze data in R, depending on the type of data and the analysis you want to perform. Some common methods for analyzing data in R include:


  • Descriptive statistics: You can use the summary() function to calculate basic descriptive statistics such as mean, median, and standard deviation for numeric data. You can also use the table() function to create frequency tables for categorical data.

  • Visualization: You can use the ggplot2 package to create visualizations such as scatter plots, bar charts, and histograms to explore the relationships and patterns in your data.

  • Regression analysis: You can use the lm() function to fit a linear regression model to your data and predict the response variable based on the predictor variables.

  • Clustering: You can use the kmeans() function to cluster your data into groups based on similarity, and use the plot() function to visualize the clusters.

  • Time series analysis: You can use the forecast() function from the "forecast" package to fit a time series model to your data and make predictions about future values.


Days of activity...

This is a common case as far as I can see. Make a table with variables activity where activity is a number from 1 to 5 and dates using date to transform in day names and then summarize how many days have what of the amount of activity.

In R, you can use the wday() function from the "lubridate" package to transform a column of dates into a column of week day names. You can then use the dplyr package to create a table with variables "activity" and "weekday", where "activity" is a number from 1 to 10 and "weekday" is the week day name for the corresponding date. Finally, you can use the summarize() function from the "dplyr" package to summarize the number of days for each activity.

For example, the following code uses the wday() and summarize() functions to create a table with variables "activity" and "weekday", and to summarize the number of days for each activity:

library(lubridate)

library(dplyr)

mydata <- data.frame(date = as.Date(c("2022-01-01", "2022-02-01", "2022-03-01", "2022-03-02", "2022-03-03")),

activity = c(1, 2, 3, 4, 5))

mydata %>%

mutate(weekday = wday(date)) %>%

group_by(activity, weekday) %>%

summarize(count = n())

In this example, the wday() function is applied to each value in the "date" column of the "mydata" data frame, and the resulting week day names are stored in the new "weekday" column. Then, the group_by() function groups the data by the "activity" and "weekday" variables, and the summarize() function counts the number of days for each group.

For example, the following code uses the wday() and summarize() functions to create a table with variables "activity" and "weekday", and to summarize the number of days for each activity:

library(lubridate)

library(dplyr)

mydata <- data.frame(date = as.Date(c("2022-01-01", "2022-02-01", "2022-03-01", "2022-03-02", "2022-03-03")),

activity = c(1, 2, 3, 4, 5))

mydata %>%

mutate(weekday = wday(date)) %>%

group_by(activity, weekday) %>%

summarize(count = n())


The resulting table shows the number of days for each activity and week day name, as shown below:


    • activity weekday count
    • 1 Saturday           1
    • 2 Sunday          1
    • 3 Wednesday  2
    • 4 Wednesday  1
    • 5 Wednesday  1

In this example, there is one day with activity 1 on Saturday, one day with activity 2 on Sunday, two days with activity 3 on Wednesday, one day with activity 4 on Wednesday, and one day with activity 5 on Wednesday.

and then...

transform activity number from the above table to values 1=very low activity, 2=low activity, 3=medium activity, 4=good activity, 5=strong activity

In R, you can use the mutate() function from the "dplyr" package to transform the values of a column in a data frame. For example, the following code uses the mutate() function to transform the "activity" column of the "mydata" data frame from numbers 1 to 5 to the corresponding activity level:

library(dplyr)
mydata <- data.frame(activity = c(1, 2, 3, 4, 5))
mydata %>%
mutate(activity = case_when(activity == 1 ~ "very low activity",
activity == 2 ~ "low activity",
activity == 3 ~ "medium activity",
activity == 4 ~ "good activity",
activity == 5 ~ "strong activity"))

In this example, the mutate() function uses the case_when() function to replace the values in the "activity" column with the corresponding activity level. The resulting data frame has the transformed "activity" column, as shown below:

  • activity
  • very low activity
  • low activity
  • medium activity
  • good activity
  • strong activity

In conclusion, the mutate() function from the "dplyr" package is a useful tool for transforming the values of a column in a data frame. You can use the case_when() function within the mutate() function to specify the transformation rules for each value in the column. 

In R, you can use the wday() function from the "lubridate" package to transform a column of dates into a column of week day names. You can then use the dplyr package to create a table with variables "activity", "weekday", and "count", where "activity" is the activity level, "weekday" is the week day name for the corresponding date, and "count" is the number of days for each activity and week day name.

For example, the following code uses the wday() and summarize() functions to create a table with variables "activity", "weekday", and "count", and to summarize the number of days for each activity and week day name:

library(lubridate)
library(dplyr)
mydata <- data.frame(date = as.Date(c("2022-01-01", "2022-02-01", "2022-03-01", "2022-03-02", "2022-03-03")),
activity = c(1, 2, 3, 4, 5))
mydata %>%
mutate(weekday = wday(date),
activity = case_when(activity == 1 ~ "very low activity",
activity == 2 ~ "low activity",
activity == 3 ~ "medium activity",
activity == 4 ~ "good activity",
activity == 5 ~ "strong activity")) %>%
group_by(activity, weekday) %>%
summarize(count = n())

The resulting table shows the number of days for each activity and week day name, as shown below:

show the table above

The resulting table shows the number of days for each activity and week day name, as shown below:




In this example, there is one day with very low activity on Saturday, one day with low activity on Sunday, two days with medium activity on Wednesday, one day with good activity on Wednesday, and one day with strong activity on Wednesday.

In conclusion, the wday() and summarize() functions from the "lubridate" and "dplyr" packages are useful tools for creating a table with variables "activity", "weekday", and "count", and for summarizing the number of days for each activity and week day name in R. 

Binomial Distribution in very simple words

The binomial distribution is a probability distribution that describes the outcome of a series of independent "yes/no" experiments...